一个登陆页面login所提交的name和password提交给loginServlet处理,loginServlet负责连接sql,如果输入的name和pas相同转交给say.html(留言板,这我就不发了),用了RequestDispatcher转发给say,直接出现404,经过out的调试只发现能进入if中的语句块,如果输入错误else抛出System.out.println("数据库出错"+ee);啥回事?
登陆login(重要的代码)
---------------------------------------#
<form action="servlet/loginSerlvet" method="post">
姓名:<input type="text" name="name"><br>
密码:<input type="password" name="password"><br>
<input type="submit" value="提交">
</form>
---------------------------------------#
loginServlet
----------------------------------------"
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312"

;
PrintWriter out = response.getWriter();
Connection con =null;
PreparedStatement pstmt = null;
String name = request.getParameter("name"

;
String password = request.getParameter("password"

;
String select = "select * from login where name=? and password=?";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"

;
}catch(Exception ex){
System.out.println("数据库连接出错"+ex);
}
try
{
con = DriverManager.getConnection("jdbc

dbc:test","sa","sa"

;
pstmt = con.prepareStatement(select);
pstmt.setString(1,name);
pstmt.setString(2,password);
ResultSet rs = pstmt.executeQuery();
if(rs.next())
{
out.println("进来了"

;
}else{
out.println("over"

;
}
try
{
rs.close();
pstmt.close();
con.close();
}catch(Exception exe){
System.out.println("111"+exe);
}
}catch(Exception ee){
System.out.println("数据库出错"+ee);
}
}
[
本帖最后由 Madrid_guti 于 2008-5-17 22:41 编辑 ]