类似问卷调查的多个jsp提交时候出现问题
想做个类似问卷调查的项目,现在试着做鞋最简单的测试。我先写了两个jsp,在这两个jsp中每个都有一个文本显示的问题,只需回答yes或者no,yes和no是用下拉框显示的,默认是no。在用户回答完两个jsp的问题后将所有结果提交到第三个jsp中,在第三个jsp中做一个简单的分析,我现在只是测试,所以只要能输出几个yes,几个no就行了。我试着写了,可是问题很多。目前的问题是jsp中调用函数返回不了actionType值,总是null,不知道怎么回事。贴出来让大家看看,不知道我的想法能不能最后跑通
jsp1:
<%@page import="com.hubin.servlet.*"%>
<%@page import="java.util.*"%>
<html>
<head>
<title>CMMI TEST</title>
<script language="JavaScript" fptype="dynamicoutline">
function next(){
document.form1.submit();
window.location = '<%=request.getContextPath()%>/Untitled-2.jsp?';
}
function getSelect1(){
document.form1.actionType.value = "select1";
document.form1.submit();
}
</script>
<style>
</style>
</head>
<form name = "form1" action="Select" method="POST">
<div align="center">
<center>
<table border="0" width="100%">
<tr>
<td>
<ul style="font-family: Arial; font-size: 10pt; text-align: left" type="square" dynamicoutline initcollapsed>
<li><font size="2">1.Requirements are managed and inconsistencies with project
plans and work products are identified</font>
</li>
</ul>
</td>
<td width="70" height="10" valign="top" align="center">
<p align="center">
<select size="1" name="select1" >
<option value ="1">YES</option>
<option value ="0" selected> NO </option>
</select></p>
</td>
</tr>
</table>
</center>
</div>
<hr/>
<table border="0" width="100%" id="table1">
<tr>
<td width="33%" align="left" valign="top"> </td>
<td align="center" width="33%" valign="top">
page 1 of 2 </td>
<td align="right" width="33%" valign="top">
<p align="right"><input type="submit" onclick="getSelect1()" name="ButtonName" value="Next"></td>
</tr>
</table>
</form>
</body>
</html>
jsp2:<html>
<head>
<title>CMMI TEST</title>
<style>
<!--
.cmmi { font-family: Arial; font-size: 10pt; text-align: left }
-->
</style>
<script language="JavaScript" fptype="dynamicoutline">
<!--
function getSelect(){
document.form1.actionType.value = "select2";
document.form1.submit();
function finish(){
window.open('<%=request.getContextPath()%>/Untitled-3.jsp?');
return false;
}
</script>
</head>
<form method="POST" action="Select">
<div align="center">
<table border="0" width="100%" id="table3">
<tr>
<td>
<ul style="font-family: Arial; font-size: 10pt; text-align: left" type="square" dynamicoutline initcollapsed>
<li><font size="2">9.Decisions are based on an evaluation of alternatives
using established criteria</font></li>
</ul>
</td>
<td width="70" height="10" valign="top" align="center">
<p align="center">
<select size="1" name="sel9" onchange="location.href='Untitled-3.jsp?select9='+this.value">
<option value ="1">YES</option>
<option value= "0" selected> NO </option>
</select></p>
</td>
</tr>
</table>
</div>
<hr/>
<p><input type="submit" onclick="getSelect()" name="ButtonName" value="Finish" ></p>
</form>
</body>
</html>
jsp3:
<%@page import="com.hubin.servlet.*"%>
<html>
<head>
<title>CMMI TEST</title>
<style>
</style>
</head>
<div align="center">
<table border="1" width="50%" id="table3">
<tr>
<td>
<%String select1 = (String) request.getSession().getAttribute("select1");
String select9 = (String) 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/>
<hr color="#008000" align="left" width="20%" size="10">
<hr color="#0000FF" align="left" size="10">
<p></td>
</tr>
</table>
</div>
<p> </p>
<p><a href="/elearning/modelschoice.jsp">TEST AGAIN !!</a></p>
</body>
</html>
Java文件:
package com.hubin.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
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", "");
//-- search
if ("select1".equals(actionType)) {
this.getContent1(request, response);
}
//-- add
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 getContent2(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {
try{
String select9 = request.getParameter("select9");
System.out.println("select9 ---------------- " + select9);
request.getSession().setAttribute("select9", select9);
response.sendRedirect("Untitled-3.jsp");
}catch (Exception ex) {
ex.printStackTrace();
request.getSession().setAttribute("ex", ex);
response.sendRedirect("error.jsp");
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
System.out.println("company = " + request.getParameter("company"));
System.out.println("aaa = " + request.getParameter("aaa"));
doGet(request, response);
}
}