1. 调整jsp代码
其实上面的login.jsp和register.jsp已经能运行起来了,我们这里的调整,主要是以前的基础上,添加了struts的html :form标签,以及操作后结果的提示对话框,请对比粗体部分.详细代码如下 :
Login.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message bundle="user" key="user.title" />
</title>
</head>
<script language="javascript">
function toRegister(){
document.location.href="register.do?method=toRegister";
}
</script>
<body>
<html:form action="/login.do?method=login">
<table width="50%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="46%">
</td>
<td width="54%">
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<bean:message bundle="user" key="user.welcome" />
</div>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
<div align="right">
<bean:message bundle="user" key="user.username" />
:
</div>
</td>
<td>
<input name="userName" type="text" id="userName" size="15">
</td>
</tr>
<tr>
<td>
<div align="right">
<bean:message bundle="user" key="user.password" />
:
</div>
</td>
<td>
<input name="password" type="password" id="password" size="15">
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
</div>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="Submit"
value="<bean:message bundle="user" key="user.login"/>">
<input type="reset" name="reset"
value="<bean:message bundle="user" key="user.cancel"/>">
<input type="button" name="toRegisterButton"
value="<bean:message bundle="user" key="user.register"/>" onClick="toRegister()">
</div>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
</table>
<logic:notEmpty name="loginForm" property="message">
<script>
alert("<bean:message key='${loginForm.message}' bundle='user'/>");
</script>
</logic:notEmpty>
</html:form>
</body>
</html>
Register.jsp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message bundle="user" key="user.welcome.register"/></title>
</head>
<body>
<html:form action="/register.do?method=register">
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2"><div align="center"><bean:message bundle="user" key="user.welcome.register"/></div></td>
</tr>
<tr>
<td width="45%"> </td>
<td width="55%"> </td>
</tr>
<tr>
<td><div align="right"><bean:message bundle="user" key="user.username"/>:</div></td>
<td><input name="userName" type="text" id="userName" size="20">
*</td>
</tr>
<tr>
<td><div align="right"><bean:message bundle="user" key="user.password"/>:</div></td>
<td><input name="password" type="password" id="password" size="20">
*</td>
</tr>
<tr>
<td><div align="right"><bean:message bundle="user" key="user.repassword"/>:</div></td>
<td><input name="rePassword" type="password" id="rePassword" size="20">
*</td>
</tr>
<tr>
<td><div align="right"><bean:message bundle="user" key="user.name"/>:</div></td>
<td><input name="name" type="text" id="name" size="20">
*</td>
</tr>
<tr>
<td><div align="right"><bean:message bundle="user" key="user.email"/>:</div></td>
<td><input name="email" type="text" id="email" size="20">
*</td>
</tr>
<tr>
<td><div align="right"><bean:message bundle="user" key="user.phone"/>:</div></td>
<td><input name="phone" type="text" id="phone" size="20"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="<bean:message bundle="user" key="user.register"/>">
<input type="reset" name="Submit" value="<bean:message bundle="user" key="user.cancel"/>">
</div></td>
</tr>
</table>
<logic:notEmpty name="registerForm" property="message">
<script>
alert('<bean:message key="${registerForm.message}" bundle="user"/>');
</script>
</logic:notEmpty>
</html:form>
</body>
</html>
2. 到这里,我们基本上把用户登陆,用户注册两个功能的页面到后台逻辑基本实现了,我们可以编译工程发布,访问http://localhost:8080/sshDemo/login.do?method=toLogin连接进行操作了.