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

📄 commonuserservlet.java

📁 提供房屋出租信息
💻 JAVA
字号:
package cwnu.com.servlets;

import cwnu.com.userData.*;
import java.io.IOException;
import java.io.PrintWriter;
import cwnu.com.dataiud.*;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;
import cwnu.com.admin.*;
import cwnu.com.rentInfo.*;
import cwnu.com.saleInfo.*;

public class commonUserServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public commonUserServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

         this.doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
             idudata iduInfo = new idudata();//数据的增 删 该  查
             userInfoControl infoControl = new userInfoControl();//登陆验证对象
             userInfoVo infovo = new userInfoVo();//用户信息对象
		     String action = request.getParameter("action");//动作参数
		     response.setCharacterEncoding("gbk");
            if("checkUser".equals(action))//检测用户名是否存在
            {			    
            	userInfoControl objcheck = new userInfoControl();
			    response.setContentType("text/html;charset=gbk");
			    response.setHeader("cache-control", "no-cache");
			    PrintWriter out = response.getWriter();
			    if(objcheck.checkUser(request.getParameter("username")))
			    {
				   out.print("用户已经存在");//已经存在
			    }
			    else
			    {
				   out.print("用户名称可以使用");//可以注册
			    }
			    out.flush();
			    out.close();
		    }else if("regist".equals(action)||"update".equals(action))//用户注册
		    {
		    	String isinsider= request.getParameter("isInsider");		    	
		    	String userName = request.getParameter("userName");
		    	String passWord = request.getParameter("passWord");
		    	String question = new String(request.getParameter("question").getBytes("ISO-8859-1"),"GBK");
		    	String answer = new String(request.getParameter("answer").getBytes("ISO-8859-1"),"GBK");
		    	String name = new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
		    	String gender = new String(request.getParameter("gender").getBytes("ISO-8859-1"),"GBK");
		    	String birthday = request.getParameter("year")+"-"+request.getParameter("month")+"-"+request.getParameter("day");
		    	String cardType = new String(request.getParameter("cardType").getBytes("ISO-8859-1"),"GBK");
		    	String paperNum = request.getParameter("paperNum");
		    	String area =new String( request.getParameter("area").getBytes("ISO-8859-1"),"GBK");
		    	String email = request.getParameter("email");
		    	String teleNumber = request.getParameter("teleNumber");	
		    	if(isinsider.equals("no")&&"regist".equals(action))
		    	{
		    	String insertsql = "insert into UserInfo(userName,passWord,passWordQuestion,passWordAnswer,trueName,gender,address,telephoneNumber,email,creditCard,cardType,birthday) " +
		    			"values('"+userName+"','"+passWord+"','"+question+"','"+answer+"','"+name+"','"+gender+"','"+area+"','"+teleNumber+"','"+email+"','"+paperNum+"','"+cardType+"','"+birthday+"')";
		    	if(iduInfo.iduInfo(insertsql))
		    	{
		    		JOptionPane.showMessageDialog(null, "恭喜你!注册成功");
		    		response.sendRedirect("index.jsp");
		    	}    
		    	else
		    	{
		    		JOptionPane.showMessageDialog(null, "对不起! 注册失败");
		    		response.sendRedirect("Jsp/regist.jsp");
		    	}
		    	}else if(isinsider.equals("yes")&&"regist".equals(action))
		    	{
		    		JOptionPane.showMessageDialog(null, "对不起!该用户已经存在");
		    		response.sendRedirect("Jsp/regist.jsp");
		    	}else if("update".equals(action))
		    	{
		    		String updateSql = "update UserInfo set passWord='"+passWord+"', passWordQuestion='"
		    		+question+"', passWordAnswer='"+answer+"', trueName='"+name+"', gender='"+gender+"', " +
		    				"address='"+area+"',telephoneNumber='"+teleNumber+"',email='"+email+"',creditCard='"+paperNum+"',cardType='"+cardType+"',birthday='"+birthday+"'  where userName='"+userName+"'";
		    		if(iduInfo.iduInfo(updateSql))
		    		{
		    			JOptionPane.showMessageDialog(null, "修改成功");
		    			response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
		    		}
		    		else
		    		{
		    			JOptionPane.showMessageDialog(null, "修改失败");
		    		response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
		    		}
		    	}
		    }else if("login".equals(action))//登陆验证
		    {
		    	
		    	
		    	String userName = request.getParameter("userName");//用户名
		    	String passWord = request.getParameter("passWord");//密码
		    	
		    	String purview = request.getParameter("purview");//权限
		    	System.out.println(userName+"   "+passWord);
		    	if(purview.equals("comuser"))
		    	{
		    		
		    		if(infoControl.isInsider(userName, passWord))
		    		{		 
		    			infovo =infoControl.reUIvo();
		    			response.sendRedirect("Jsp/commonUsers/rsinfo.jsp");
		    			request.getSession(true).setAttribute("uinfovo",infovo );
		    			String birthday=infovo.getBirthday();
		    			String[] date=birthday.split("-");
		    			request.getSession(true).setAttribute("year",date[0] );
		    			request.getSession(true).setAttribute("month",date[1] );
		    			request.getSession(true).setAttribute("day",date[2] );
		    			request.getSession(true).setAttribute("userid", infovo.getID());
		    			JOptionPane.showMessageDialog(null, "登陆成功");		    						
		    		}else
		    		{
		    			JOptionPane.showMessageDialog(null, "登陆失败");
		    			response.sendRedirect("index.jsp");
		    		}
		    	}else if(purview.equals("admin"))
		    	{
		    		adminInfo admin = new adminInfo();
		    		if(admin.isadmin(userName, passWord))
		    		{
		    			
		    			
		    			ArrayList<userInfoVo> ulist = new ArrayList<userInfoVo>();
		    			userList objuserlist = new userList();
		    			
		    			ulist = objuserlist.getlist();
		    			
		    			request.getSession(true).setAttribute("ulist", ulist);
		    			for(int i=0;i<ulist.size();i++)
		    			{
		    			System.out.println(ulist.get(i).getAddress());
		    			}
		    			request.getSession(true).setAttribute("adminName", userName);
		    			request.getSession(true).setAttribute("adminID", admin.reid());
		    			JOptionPane.showMessageDialog(null, "登陆成功");
		    			response.sendRedirect("Jsp/administrater/admin.jsp");
		    		}else
		    		{
		    			JOptionPane.showMessageDialog(null, "登陆失败");
		    			response.sendRedirect("index.jsp");
		    		}
		    	}
		    }else if("exit".equals(action))//退出登陆
		    {
		    	request.getSession().invalidate();
		    	response.sendRedirect("index.jsp");
		    }
		    	
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

⌨️ 快捷键说明

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