JSP新闻系统之六 后台登陆页面
  TEZNKK3IfmPf 2023年11月15日 20 0
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>用户登陆</title>
<link rel="stylesheet" href="https://www.ctyun.cn/portal/link.html?target=..%2Fcss%2Fcss.css" type="text/css"></link>
</head>
<body  bgcolor="#31827C">
<form action="login_action.jsp" method="post">
<table width="99%" height="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="100%" height="100%" align="center" valign="middle"><p> </p>
          <table width="700" height="440" border="0" align="center" cellpadding="0" cellspacing="0" background="pic/login.jpg">
            <tr>
              <td><table width="100%" height="354" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="121"> </td>
                  <td> </td>
                </tr>
                <tr>
                  <td width="62%" height="158"> </td>
                  <td width="38%" valign="bottom">
                    <table width="89%" height="99" border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <td width="30%" height="30"><div align="right">用户名:</div></td>
                        <td width="70%" height="30"><label>
                          <input type="text" name="username" size="15" style="height:22px"/>
                        </label></td>
                      </tr>
                      <tr>
                        <td height="18"><div align="right">密 码:</div></td>
                        <td height="18"><label>
                          <input type="password" name="userpwd"  size="15" style="height:22px"/>
                        </label></td>
                      </tr>
                      <tr>
                        <td height="18"><div align="right"><input type="checkbox" name="saveMessage"/></div></td>
                        <td height="18"><label>
                          		两周内自动登录
                        </label></td>
                      </tr>
                      <tr>
                        <td height="50"> </td>
                        <td height="50" valign="top"><input type="submit" value="提交">
                        <input type="reset" value="取消"></td>
                      </tr> 
                    </table>
                                    
                  </td>
                </tr>
                <tr>
                  <td height="75"> </td>
                  <td> </td>
                </tr>
              </table></td>
            </tr>
          </table>
          <p></p>
        <p> </p></td>
      </tr>
    </table>
</form>	
</body>
</html>

登陆action页面


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.news.entity.*,com.news.dao.*,com.news.dao.impl.*" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="https://www.ctyun.cn/portal/link.html?target=%26lt%3B%25%3DbasePath%25%26gt%3B">
    <title>My JSP 'login_action.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
  </head>
  
  <body>
    <%
    	//获取页面数据
    	request.setCharacterEncoding("utf-8");
    	String username=request.getParameter("username");
    	String userpwd=request.getParameter("userpwd");
    	//调用Dao方法进行查询;
    	UserDao ud=new UserDaoImpl();
    	User user=ud.queryUserByNameAndPwd(username,userpwd);
    	if(user!=null){//user:是一个登陆对象
    		//如果登陆成功,则设置当前的session
    		session.setAttribute("user",user);
    		response.sendRedirect("welcome.jsp");//成功到欢迎页面;
    	}else{
    		session.setAttribute("msg","登陆失败,请检查用户名和密码");
    		response.sendRedirect("login.jsp");//失败还回登陆页面
    	}
     %>
  </body>
</html>



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月15日 0

暂无评论

推荐阅读
TEZNKK3IfmPf