mod_user.java

来自「一个简单的网上商店系统」· Java 代码 · 共 85 行

JAVA
85
字号
package Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import JavaBean.DB_User;
import JavaBean.User;
import JavaBean.MD5_Encoding;

public class mod_user extends HttpServlet {

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

	/**
	 * 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 {

		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 {

		response.setContentType("text/html;charset=gbk");
		PrintWriter out = response.getWriter();
		DB_User dbuser=new DB_User();
		User user;
		MD5_Encoding mde=new MD5_Encoding();
		
		int userid=Integer.parseInt((String)request.getParameter("userid"));
		String username = request.getParameter("username");
		String ypwd = request.getParameter("ypwd");	
		String npwd = request.getParameter("npwd");		
		String confpwd = request.getParameter("confpwd");
		String md5ypwd=mde.getMD5ofStr(ypwd);
		String md5pwd=mde.getMD5ofStr(npwd);
		
		if(dbuser.get(username,md5ypwd)!=null){
			user=dbuser.get(username,md5ypwd);
			if(npwd.equals(confpwd)){
				if(dbuser.update_pwd(username,md5pwd)>0){
					out.println("密码修改成功!");
				}	
			}
			else{
				out.println("新密码和确认密码不同,请重新输入!");
			}
		}
		else{
			out.println("原密码不正确!");
		}
		
	}

}

⌨️ 快捷键说明

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