login 页面也web.xml页面
代码如下
login.jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="helloModel"
class="cn.javass.hello.servletimpl.vo.HelloWorldModel" scope="request"></jsp:useBean>
<jsp:setProperty property="*" name="helloModel" />
<%
if ("login".equals(helloModel.getSubmitFlag())) {
%>
<jsp:forward page="/hello"></jsp:forward>
<%
}
%>
<form action="/StrutsStudy/servletimpl/login.jsp" method="post">
<input type="hidden" name="submitFlag" value="login"> 账号:<input
type="text" name="account"><br> 密码:<input
type="password" name="password"><br> <input
type="submit" value="提交">
</form>
</body>
</html>
然后是web.xml,不贴了。。。
说明一下,元素的action属性用来指定由谁响应,由于这里使用了JavaBean来收集页面的数据,因此需要先提交到本页面,然后再转向相应的servlet进行处理。
编写欢迎界面的jsp
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="hwm"
class="cn.javass.hello.servletimpl.vo.HelloWorldModel" scope="request"></jsp:useBean>
欢迎张海为:<%=hwm.getAccount()%>的朋友的来访!
</body>
</html>
跑一下试试吧~