日期:2014-05-17  浏览次数:20759 次

求助,这个程序有问题吗,不能正常跳转
package func;

import java.io.IOException;
import java.sql.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import func.User;


public class Signin extends HttpServlet {
private static final long serialVersionUID = 1L;
private String CONTENT_TYPE = "text/html; charset=GB2312";
Connection con=null;

  public Signin() 
  {
   
 
  String sDBdriver="sun.jdbc.odbc.JdbcOdbcDriver";
  String sConnStr="jdbc:odbc:db";
 
 
  try{
  Class.forName(sDBdriver);
  con=DriverManager.getConnection(sConnStr);
  }
  catch(Exception e){
 
  }
 
  }  
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
  response.setContentType(CONTENT_TYPE);
  request.setCharacterEncoding("gb2312");
   

String s1=request.getParameter("num");
String s2=request.getParameter("password");

try {
Statement stm = con.createStatement();
ResultSet result = stm.executeQuery("select * from register where num='"+s1+"' and password='"+s2+"'");
if(result.next()){
RequestDispatcher dispatcher=request.getRequestDispatcher("/success.jsp");
dispatcher.forward(request, response);
}
else{
RequestDispatcher dispatcher=request.getRequestDispatcher("/signin.jsp");
dispatcher.forward(request, response);
}

con.close();
} catch (Exception e) {}

 
 



}


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


}



}


------解决方案--------------------
RequestDispatcher dispatcher=request.getRequestDispatcher("/success.jsp");
dispatcher.forward(request, response)
把两句合并起来试试
RequestDispatcher dispatcher=request.getRequestDispatcher("/success.jsp").forward(request,response)还不行把错误信息列出来
------解决方案--------------------
探讨

RequestDispatcher dispatcher=request.getRequestDispatcher("/success.jsp");
dispatcher.forward(request, response)
把两句合并起来试试
RequestDispatcher dispatcher=request.getRequestDispatcher("/success.jsp")……

------解决方案--------------------
用这个试试 Response.Redirect("xxx.jsp")
或者你看看是不是你jsp页的路径打错了


------解决方案--------------------
你的代码很多异常都没有处理、 只是捕获了而已 、并没处理、

你的意思是跳错了页面还是显示问题 是想跳到/success.jsp还是/signin.jsp

你的WebRoot 或 WebContent 下有这俩个文件么、


------解决方案--------------------
这个很明显是有异常,没有进i