爱问知识人 爱问教育 医院库

java 如何做登录的判断?

首页

java 如何做登录的判断?

匿名、用户名、密码
选中“匿名”,提交成功;
不选中,判断用户名、密码是否正确
如何实现?

提交回答
好评回答
  • 2007-11-08 23:12:15
      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了。
      

    j***

    2007-11-08 23:12:15

其他答案

    2007-11-08 23:00:35
  • 如果选择匿名,那么要重定向到正常的页面,但是要给某个变量或者session赋值,将来用于设置权限什么的。如果没有选中匿名,那么要在数据库中查询是否有该用户名的用户,如果没有提示没有此用户,如果有那么要在比对密码是否正确,如果不正确提示密码错误。如果正确那么重定向到正常的页面。

    1***

    2007-11-08 23:00:35

类似问题

换一换

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 176-195
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):