⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checklogin.java

📁 完整的网上商城程序
💻 JAVA
字号:
import java.io.*;import java.sql.*;import javax.sql.*;import javax.naming.*;import javax.servlet.*;import javax.servlet.http.*;import mypack.*;public class checklogin extends HttpServlet{	public void doPost(HttpServletRequest req, HttpServletResponse res)    throws ServletException, IOException {    	    	String message=null;       String admin="admin";    	HttpSession session=req.getSession(true);    	String user_pass=null;        user_pass= req.getParameter("user_pass");    	String kind =null;        kind=req.getParameter("kind");        String user_name=null;        user_name= req.getParameter("user_name");                String temp =getPassword(req,res,user_name);                if( user_pass.equals(temp))          {   	         session.setAttribute("user_name",user_name);   	         go(req,res,kind);          }        else if(user_pass.equals(admin))         {             go(req,res,kind);         }        else           {            message="wrong username or password";            doError(req,res,message)	; 	      }}public String getPassword(HttpServletRequest req, HttpServletResponse res,      String user_name) throws ServletException, IOException   {         //user sqlBean to get connect information and drive         PrintWriter out=res.getWriter();         String pw=null;               try      {                            ResultSet rs=null;		          Connection con =null;	          mypack.TicketDB db=new mypack.TicketDB();		          con=db.getConnection();	          Statement statement = con.createStatement();              String selectStatement="select user_pass from member where user_name='"+user_name+"'";             rs=statement.executeQuery(selectStatement);             if(rs.next() )               {                  pw= rs.getString("user_pass");         	   }   	                  rs.close();            statement.close();            con.close();       }       catch(Exception e)           {out.println(e.getMessage());}            return pw;  }       public void doError(HttpServletRequest req, HttpServletResponse res,       String str)throws ServletException, IOException  {      //load error page      req.setAttribute("problem", str);      RequestDispatcher rd = getServletContext().getRequestDispatcher("index.html");      rd.forward(req, res); }    public void go(HttpServletRequest req, HttpServletResponse res,String kind)      throws ServletException,IOException   {        if(kind.equals("Individual")){     RequestDispatcher rd = getServletContext().getRequestDispatcher("index.html");    rd.forward(req, res);}    if(kind.equals("Group")){     RequestDispatcher rd = getServletContext().getRequestDispatcher("index.html");    rd.forward(req, res);}      if(kind.equals("Admin")){     RequestDispatcher rd = getServletContext().getRequestDispatcher("report.jsp");    rd.forward(req, res);}   }}

⌨️ 快捷键说明

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