dengluservlet.java

来自「登录 使用了Ajax 还有重设密码的功能」· Java 代码 · 共 48 行

JAVA
48
字号
package servlet;
import connection.database.*;
import java.io.*;
import bean.login.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import DAO.*;
public class DengluServlet extends HttpServlet
{
	public void init(ServletConfig config) throws ServletException
	{
		super.init(config);
	}
	public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
	{
		response.setContentType("text/html;charset=gb2312");
		//接收并处理从Login.jsp提交上的信息
		String yourId=request.getParameter("id");//用户名
		System.out.println("yourId="+yourId);
		try{
			byte[]bb=yourId.getBytes("gb2312");
			yourId=new String(bb,"ISO-8859-1");
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		String yourPassword=request.getParameter("password");//密码
		System.out.println("yourPassword="+yourPassword);
		String s=null;
	    
	    DAO dao=new DAO();
	    if(dao.lookDenglu(yourId,yourPassword)){
	    	s=yourId+"已登录!";
	    }else
		  {
		       s="登录失败,用户名或密码错误!";
		  }	 
		request.getSession().setAttribute("denglu",s);
	    //将servlet请求转发给denglu.jsp
	    RequestDispatcher dispather=request.getRequestDispatcher("denglu.jsp");
	    dispather.forward(request,response);
	} 
	public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
	{
		doPost(request,response);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?