Jsp:传送并显示数据的问题

hubinjisu 2008-12-24 10:39:12
我现在做了3个jsp还有一个servlet。思路很简单,就是经过两个jsp,将获取的值传到第三个jsp中并显示出来,可是问题却不少。请指点,谢谢。
第一个jsp中:
<script language="JavaScript" fptype="dynamicoutline">
function getSelect1(){
document.form1.actionType.value = "select1";
document.form1.submit();
}

</script>
<form name = "form1" action="Select" method="POST">
<input type="hidden" name="actionType" value=""/>
...
<p align="center">
<select size="1" name="select1" >

<option value ="1">YES </option>
<option value ="0" selected> NO </option>
</select> </p>
<td align="right" width="33%" valign="top">
<p align="right"> <input type="button" onclick="getSelect1()" name="ButtonName" value="Next"> </td>
....
第二个jsp内容几乎很第一个一样
在第三个jsp中显示获取的值:
<p align="center"><b><font face="Arial" size="6">(Initial)</font></b></p><br/>
<%String select1 = request.getSession().getAttribute("select1");
String select9 = request.getSession().getAttribute("select9");
/%>
<p align="center"><b><font face="Arial" size="6">"+select1+"</font></b></p><br/>
<p align="center"><b><font face="Arial" size="6">"+select9+"</font></b></p><br/>

servlet的java函数Select.java:
public class Select extends HttpServlet{

// Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
try {

String actionType = request.getParameter("actionType");
System.out.println("actionType ----------- " + actionType);

request.getSession().setAttribute("retMsg", "");

if ("select1".equals(actionType)) {
this.getContent1(request, response);
}

else if ("select2".equals(actionType)) {
this.getContent2(request, response);
}

} catch (Exception ex) {
ex.printStackTrace();
request.getSession().setAttribute("ex", ex);
response.sendRedirect("error.jsp");
}
}

public void getContent1(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {


try{
String select1 = request.getParameter("select1");

System.out.println("select1 ---------------- " + select1);
request.getSession().setAttribute("select1", select1);

response.sendRedirect("Untitled-2.jsp");

}catch (Exception ex) {
ex.printStackTrace();
request.getSession().setAttribute("ex", ex);
response.sendRedirect("error.jsp");
}
}

public void getContent1(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {... }
目前的问题是第一个和第二个jsp中按钮button点击后无法调用函数getSelect1(),不知道什么原因。后来我将button的type改为submit直接调试一下,java函数可能没有问题,因为能获取到值,可是在将值传到第三个jsp时候却有问题,接受不到值并出现错误:严重:
Javac exception
Compile failed; see the compiler error output for details.
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:944)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:764)
...
...全文
122 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
hubinjisu 2008-12-25
  • 打赏
  • 举报
回复
我试过了,还是没有任何反应,难道我电脑坏了不成?
tianqiao1689 2008-12-25
  • 打赏
  • 举报
回复
lz,我建议将‘document.form1.actionType.value = "select1"; ’,改为传递一个url,就是你的第二个页面,然后试试
hubinjisu 2008-12-25
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 freedomTTT 的回复:]
把onclick()事件改成onsubmit()试下
[/Quote]
我将按钮的属性type改成submit试过了,能通过。可是我的目的不是立即提交,而是调用按钮函数来给actionType赋个值,以便判断调用哪个函数的。问题是按钮函数始终无法调用,我很迷茫
hubinjisu 2008-12-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 txg0426 的回复:]
document.form1.actionType.value = "select1";
这一行是将字符串“select1”赋给了actionType,应该是
document.form1.actionType.value = document.form1.select1.value;
[/Quote]
这里我的目的就是要将字符串赋值给actionType,然后在servlet里通过判断返回的值去选择要执行的函数
jxsqs 2008-12-25
  • 打赏
  • 举报
回复
ding
success000 2008-12-25
  • 打赏
  • 举报
回复
ding
authenticationf 2008-12-25
  • 打赏
  • 举报
回复
mark
freedomTTT 2008-12-25
  • 打赏
  • 举报
回复
把onclick()事件改成onsubmit()试下
success000 2008-12-25
  • 打赏
  • 举报
回复
mark
txg0426 2008-12-25
  • 打赏
  • 举报
回复
document.form1.actionType.value = "select1";
这一行是将字符串“select1”赋给了actionType,应该是
document.form1.actionType.value = document.form1.select1.value;
watson110 2008-12-25
  • 打赏
  • 举报
回复
首页传递的时候跟上参数 ?actionType=
hubinjisu 2008-12-25
  • 打赏
  • 举报
回复
我在getSelect函数里添加了个弹出对话框进行测试,可是还是一点反应都没有,说明是jsp里的getSelect函数根本无法调用到,不知道为什么!
hubinjisu 2008-12-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lin52p 的回复:]
你表单提交的方式是“post”
而你SERVER中只在"post"中转换数据

当然没显示啊
[/Quote]
函数我没有贴完,其实我写了doPost函数的:
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {

doGet(request, response);
}
lin52p 2008-12-24
  • 打赏
  • 举报
回复
你表单提交的方式是“post”
而你SERVER中只在"doget"中转换数据

当然没显示啊

在doget方法的第一句加一句this.dopost()

就可以了
lin52p 2008-12-24
  • 打赏
  • 举报
回复
你表单提交的方式是“post”
而你SERVER中只在"post"中转换数据

当然没显示啊

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧