java 如何做登录的判断?
匿名、用户名、密码 选中“匿名”,提交成功; 不选中,判断用户名、密码是否正确 如何实现?
public class LoginServlet extends tp。HttpServlet implements rvlet。Servlet { //构造函数 public LoginServlet() { super(); } //服务器端的验证、提交处理 protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { tContentType("text/html;charset=GB2312"); MD5_Encoding md5=new MD5_Encoding(); // 获取提交的用户名: String UserName = tParameter("logname"); // 获取提交的密码: String Password = tParameter("logpwd"); // 对密码进行MD5数据加密 String EnPwd = tMD5ofStr(Password); String random = tParameter("random"); String random2 = tSession()。
getAttribute("random")。toString(); if (!random。equals(random2)) { tAttribute("error", "输入的验证码不正确!"); try { tRequestDispatcher("Login。
jsp")。forward(request, response); } catch (Throwable t) { getServletContext()。log( tMessage()); } } //核对用户名和密码,决定是否通过登陆验证 DB_User dbuser = new DB_User(); User user = t(UserName, EnPwd); if (user != null) { // 登录成功时,把strUserName设成session变量UserName tSession(true)。
setAttribute("username", UserName); try { tRequestDispatcher("Welcome1。jsp")。forward(request,response); } catch (Throwable t) { getServletContext()。
log( tMessage()); } } else { // 否则为游客身份 tSession(true)。setAttribute("username", UserName); try { tRequestDispatcher("Welcome1。
jsp")。forward(request, response); } catch (Throwable t) { getServletContext()。log( tMessage()); } } } } 一年前写的了 提交后,在JSP中再对username判断一下就OK了。
如果选择匿名,那么要重定向到正常的页面,但是要给某个变量或者session赋值,将来用于设置权限什么的。如果没有选中匿名,那么要在数据库中查询是否有该用户名的用户,如果没有提示没有此用户,如果有那么要在比对密码是否正确,如果不正确提示密码错误。如果正确那么重定向到正常的页面。
问:提交的舰队司令,用户名或密码错误,请重新填写舰队司令用户名及密码
答:您的舰队提交内容有误,请按照主页要求重新提交。详情>>
答:google "java 缓冲池"详情>>
答:百度里搜张孝祥 非常好的视频教程详情>>