jsp简单实现新闻发布系统中用户注册确认和用户模拟登录功能的开发
<jsp:include page="common/top.jsp" />
以及left和bottom为三个公共页面
主页面为index.jsp
简单的实现了可以设置用户名和登录等功能
Login.jsp
<%@page language="java" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>新闻发布系统 V3</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<jsp:include page="common/top.jsp" />
<div id="content">
<aside>
<jsp:include page="common/left.jsp" />
</aside>
<main> <!-- main begin -->
<section class="inputform">
<form action="doLogin.jsp" method="post">
<input type="text" name="username" placeholder="用户名"
required="required" /> <br><br>
<input type="password" name="password" placeholder="登录密码"><br>
自动登录:
<input type="radio" name="nopwd" value="<%=60*60*24*7%>">一周
<input type="radio" name="nopwd" value="<%=60*60*24*15%>">半个月
<input type="radio" name="nopwd" value="<%=60*60*24*31%>">一个月
<input type="radio" name="nopwd" value="<%=0%>">不启用
<br> <br>
<input type="submit" value="登录"></input>
<a href="userRegister.jsp">用户注册</a><br>
</form>
</section>
<!--main end -->
</main>
<div class="blank20"></div>
<div class="blank10"></div>
</div>
<%@include file="common/bottom.txt"%>
</body>
</html>
doLogin.jsp
<%@page language="java" contentType="text/html;charset=utf-8"%>
<%
request.setCharacterEncoding("utf-8");
String name = request.getParameter("username");
String pwd = request.getParameter("password");
if (("lzy".equals(name) && "123".equals(pwd)) || ("admin".equals(name) && "456".equals(pwd))) {
session.setAttribute("username", name);
//免密码自动登录
String nopwd = request.getParameter("nopwd");
if (nopwd != null) {
Cookie cookie = new Cookie("autologin", name + "-" + pwd);
cookie.setMaxAge(Integer.parseInt(nopwd));
cookie.setPath(request.getContextPath());
response.addCookie(cookie);
}
response.sendRedirect("index.jsp");
} else {
response.sendRedirect("Login.jsp");
}
%>
userRegister.jsp
<%@page language="java" contentType="text/html;charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>新闻发布系统V3</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<jsp:include page="common/top.jsp" />
<div id="content">
<aside>
<jsp:include page="common/left.jsp" />
</aside>
<main>
<!-- main begin -->
<section class="inputform">
<div class="top-bar">
<h1>用户注册</h1>
</div>
<br/>
<form action="userVeriRegister.jsp" method="post">
用户名:<input type="text" name="username"></input><br/>
密码:<input type="password" name="password"></input><br/>
性别: 男<input type="radio" value="male" name="gender">
女<input type="radio" value="female" name="gender"><br/>
居住地:
<select name="City" >
<option value="BeiJing" name="place">北京市</option>
<option value="ShangHai" name="place">上海市</option>
<option value="TianJin" name="place">天津市</option>
</select><br/>
就业方式:
<input type="checkbox" name="JOB" value="trainning">通过培训
<input type="checkbox" name="JOB" value="recommend">通过推荐
<input type="checkbox" name="JOB" value="selfstudy">通过自学<br/>
留言:
<textarea name="msg" rows="4" cols="60"></textarea><br/>
个人简介:
<textarea name="resume" cols="12" rows="6"></textarea>
<br/><input type="submit" value="提交"></input><br/>
</form>
</section>
<!--main end -->
</main>
<div class="blank20"></div>
<div class="blank10"></div>
</div>
<%@include file="common/bottom.txt"%>
</body>
</html>
userVeriRegister.jsp
<%@page language="java" contentType="text/html;charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
<title>新闻发布系统V3</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<jsp:include page="common/top.jsp" />
<div id="content">
<aside>
<jsp:include page="common/left.jsp" />
</aside>
<main>
<!-- main begin -->
<section class="inputform">
<div class="top-bar">
<h1>注册确认</h1>
</div>
<%
request.setCharacterEncoding("utf-8");
String uName = request.getParameter("username");
String uPwd = request.getParameter("password");
String uGender = request.getParameter("gender");
String uResume = request.getParameter("resume");
String uPlace = request.getParameter("place");
String uJob = request.getParameter("JOB");
String uMsg = request.getParameter("msg");
%>
<table>
<tr>
<td>用户名:</td>
<td><%=uName%></td>
</tr>
<tr>
<td>密码:</td>
<td><%=uPwd%></td>
</tr>
<tr>
<td>性别:</td>
<td><%=uGender%></td>
</tr>
<tr>
<td>个人简介:</td>
<td><%=uResume%></td>
</tr>
<tr>
<td>居住地:</td>
<td><%=uPlace%></td>
</tr>
<tr>
<td>就业方式:</td>
<td><%=uJob%></td>
</tr>
<tr>
<td>留言::</td>
<td><%=uMsg%></td>
</tr>
</table>
</section>
<!--main end -->
</main>
<div class="blank20"></div>
<div class="blank10"></div>
</div>
<%@include file="common/bottom.txt"%>
</body>
</html>