html跳转servlet出错,jsp页面跳转servlet时出现404的错误

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

这是HandleLoogin.java文件

package loog;

import up.*;//bean的包

import java.sql.*;

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class HandleLoogin extends HttpServlet

{ public void init(ServletConfig config) throws ServletException

{ super.init(config);

try { Class.forName("com.mysql.jdbc.Driver");

}

catch(Exception e){}

}

public String handleString(String s)

{ try{ byte bb[]=s.getBytes("iso-8859-1");

s=new String(bb,"GB2312");

}

catch(Exception ee){}

return s;

}

public void doPost(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException

{ Connection con;

PreparedStatement sql;

Loogin looginBean=null;

String backNews="";

HttpSession session=request.getSession(true);

try{ looginBean=(Loogin)session.getAttribute("loogin");

if(looginBean==null)

{ looginBean=new Loogin();

session.setAttribute("loogin",looginBean);

}

}

catch(Exception ee)

{ looginBean=new Loogin();

session.setAttribute("loogin",looginBean);

}

String loogname=request.getParameter("loogname").trim(),

password=request.getParameter("password").trim();

boolean ok=looginBean.getSuccess();

loogname=handleString(loogname);

password=handleString(password);

if(ok==true&&loogname.equals(looginBean.getLoogname()))

{ backNews=loogname+"已经登录了";

looginBean.setBackNews(backNews);

}

else

{ String uri="jdbc:mysql://localhost/test";

boolean boo=(loogname.length()>0)&&(password.length()>0);

try{ con=DriverManager.getConnection(uri,"shuju","");

String condition="select * from student where logname =? and password =?";

sql=con.prepareStatement(condition);

if(boo)

{ sql.setString(1,loogname);

sql.setString(2,password);

ResultSet rs=sql.executeQuery();

boolean m=rs.next();

if(m==true)

{ backNews="登录成功";

looginBean.setBackNews(handleString(backNews));

looginBean.setSuccess(true);

looginBean.setLoogname(loogname);

}

else

{ backNews="您输入的用户名不存在,或密码不般配";

looginBean.setBackNews(handleString(backNews));

looginBean.setSuccess(false);

looginBean.setLoogname(loogname);

looginBean.setPassword(password);

}

}

else

{ backNews="您输入的用户名不存在,或密码不般配";

looginBean.setBackNews(handleString(backNews));

looginBean.setSuccess(false);

looginBean.setLoogname(loogname);

looginBean.setPassword(password);

}

con.close();

}

catch(SQLException exp)

{ backNews=""+exp;

looginBean.setBackNews(backNews);

looginBean.setSuccess(false);

}

}

RequestDispatcher dispatcher=request.getRequestDispatcher("showLooginMess.jsp");

dispatcher.forward(request, response);

}

public void doGet(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException

{ doPost(request,response);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值