2 afanxingzhou afanxingzhou 于 2014.10.15 22:56 提问

jsp页面调用Servlet后进入Servlet页面空白不跳转了

各位大大,小弟正在用java做毕业设计,遇到一个问题,就是想实现获取页面的学生姓名sname和学号sno,然后到数据库中执行查询,将这个学生的成绩从数据库中输出到新的页面。可是,问题来了:在查询页面点击提交按钮后,页面跳转到ChengjiServlet2页面,web浏览器就一片空白,在ChengjiServlet2页面的sendRedirect也没了作用。。。希望各位大大们看在我操心做毕业设计的份儿上帮帮我吧,说白了就是一个查询输出,望大大们指点!跪谢!!
//查询页面,jsp。放在一个文件夹里。路径没出错
不支持直接使用html标签,所以我改了一下
《body》
《form id="form1" name="chengjiFrom" method="post" action="../ChengjiServlet2"》《h1 align="center"》成绩查询页面《/h1》
《p>姓名:
《input name="sname" type="text" id="sname" />
《/p>
《p>学号:
《input name="sno" type="text" id="sno" />
《/p>
《p>
《input type="submit" name="Submit" value="查询成绩" />
《/p>
《/form>
《/body>

//这是我编写的ChengjiServlet2类
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List chengji = new ArrayList();
//获取chengjichaxun.jsp页面的各个控件属性
String Sname = request.getParameter("sname");
String Sno = request.getParameter("sno");
String SelectScore = request.getParameter("select");

    ChengjiSQLUtil chengjiSql = new ChengjiSQLUtil();
    Connection conn =null;
    Statement stmt=null;
    ResultSet rs = null;
    conn = chengjiSql.getConn_Bendi();

    try
        {
            if(SelectScore.equals("score_1"))
          {
            //创建Statement实例,并执行sql语句
            String sql = "SELECT * FROM 'renwu'.'score_da1' where sno='"+Sno+"' and sname='"+Sname+"'";

            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);
            while(rs.next())
            {
            String sno = rs.getString("sno");
            String sname = rs.getString("sname");
            String ke1_a = rs.getString("ke1_a");
            String ke1_b = rs.getString("ke1_b");
            String ke1_c = rs.getString("ke1_c");
            String ke1_d = rs.getString("ke1_d");
            String ke1_e = rs.getString("ke1_e");
            String ke1_f = rs.getString("ke1_f");
            chengji.add(sno);
            chengji.add(sname);
            chengji.add(ke1_a);
            chengji.add(ke1_b);
            chengji.add(ke1_c);
            chengji.add(ke1_d);
            chengji.add(ke1_e);
            chengji.add(ke1_f);
            }
            HttpSession session = request.getSession();
            session.setAttribute("score", chengji);

response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp");
}
else if(SelectScore.equals("score_2"))
{
String sql = "SELECT * FROM 'renwu'.'score_da2' where sno='"+Sno+"' and sname='"+Sname+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
String sno = rs.getString("sno");
String sname = rs.getString("sname");
String ke2_a = rs.getString("ke2_a");
String ke2_b = rs.getString("ke2_b");
String ke2_c = rs.getString("ke2_c");
String ke2_d = rs.getString("ke2_d");
String ke2_e = rs.getString("ke2_e");
String ke2_f = rs.getString("ke2_f");
chengji.add(sno);
chengji.add(sname);
chengji.add(ke2_a);
chengji.add(ke2_b);
chengji.add(ke2_c);
chengji.add(ke2_d);
chengji.add(ke2_e);
chengji.add(ke2_f);
}
HttpSession session = request.getSession();
session.setAttribute("score", chengji);
response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp");
}
else if(SelectScore.equals("score_3"))
{
String sql = "SELECT * FROM 'renwu'.'score_da3' where sno='"+Sno+"' and sname='"+Sname+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
String sno = rs.getString("sno");
String sname = rs.getString("sname");
String ke3_a = rs.getString("ke3_a");
String ke3_b = rs.getString("ke3_b");
String ke3_c = rs.getString("ke3_c");
String ke3_d = rs.getString("ke3_d");
String ke3_e = rs.getString("ke3_e");
String ke3_f = rs.getString("ke3_f");
chengji.add(sno);
chengji.add(sname);
chengji.add(ke3_a);
chengji.add(ke3_b);
chengji.add(ke3_c);
chengji.add(ke3_d);
chengji.add(ke3_e);
chengji.add(ke3_f);
}
HttpSession session = request.getSession();
session.setAttribute("score", chengji);
response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp");
}
else if(SelectScore.equals("score_4"))
{
String sql = "SELECT * FROM 'renwu'.'score_da4' where sno='"+Sno+"' and sname='"+Sname+"'";
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next())
{
String sno = rs.getString("sno");
String sname = rs.getString("sname");
String ke4_a = rs.getString("ke4_a");
String ke4_b = rs.getString("ke4_b");
String ke4_c = rs.getString("ke4_c");
String ke4_d = rs.getString("ke4_d");
String ke4_e = rs.getString("ke4_e");
String ke4_f = rs.getString("ke4_f");
chengji.add(sno);
chengji.add(sname);
chengji.add(ke4_a);
chengji.add(ke4_b);
chengji.add(ke4_c);
chengji.add(ke4_d);
chengji.add(ke4_e);
chengji.add(ke4_f);
}
HttpSession session = request.getSession();
session.setAttribute("score", chengji);
response.sendRedirect("chaxun_chengji/chengji_jieguo.jsp");
}
}catch(Exception e)
{
e.printStackTrace();
}finally
{
chengjiSql.releaseResources(conn, stmt, rs);
}
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request,response);
}

//这块是web.xml的相关信息

chengjiServlet2
org.afan.course.servlet.ChengjiServlet2


chengjiServlet2
/chengjiServlet2

//这块是查询成功后要跳转的页面代码,目前还没能走到这个页面。我用list将数据输出,因为不会其他的将java类查询结果输出到jsp页面的方法。。
《body>

成绩情况


《table>
<%
List list = (List)session.getAttribute("score");
for(int i=0;i {
out.print("成绩:" + list.get(i) + "
");
}

%>
《/table>
《/body>

2个回答

ahnu120705097
ahnu120705097   2014.10.15 23:50
已采纳

我建议你把chengji_jieguo.jsp嵌入到ChengjiServlet2.jsp里看看,而不是跳转。具体代码问题我也没看出些啥来,毕竟你贴的代码也不全。数据库连接要加上try。。。catch捕捉一下异常

sinat_33898916
sinat_33898916   2016.02.25 10:11

我也遇到了同样的问题,请问你最后是怎么解决的

Csdn user default icon
上传中...
上传图片
插入图片