程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> javaweb-jsp頁面調用Servlet後進入Servlet頁面空白不跳轉了

javaweb-jsp頁面調用Servlet後進入Servlet頁面空白不跳轉了

編輯:編程綜合問答
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>

最佳回答:


我建議你把chengji_jieguo.jsp嵌入到ChengjiServlet2.jsp裡看看,而不是跳轉。具體代碼問題我也沒看出些啥來,畢竟你貼的代碼也不全。數據庫連接要加上try。。。catch捕捉一下異常

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved