本文的示例将创建几个页面,每个页面将会有一些信息需要用户填写,最后将这几个信息全部收集起来呈现。这就是分布式收集数据。
1.数据收集页面
step1.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <!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=GB18030"> <title>用户信息</title> </head> <body> <h1>用户信息</h1><hr> <form action="step1.do" method="post"> 姓名:<input type="text" name="username"/><br> <input type="submit" value="下一步"/> </form> </body> </html> |
step2.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <!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=GB18030"> <title>产品信息</title> </head> <body> <h1>产品信息</h1><hr> <form action="step2.do" method="post"> <input type="checkbox" name="productID" value="1"/>产品1<br> <input type="checkbox" name="productID" value="2"/>产品2<br> <input type="checkbox" name="productID" value="3"/>产品3<br> <input type="checkbox" name="productID" value="4"/>产品4<br> <input type="checkbox" name="productID" value="5"/>产品5<br><p> <input type="submit" value="下一步"/> </form> </body> </html> |
step3.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <!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=GB18030"> <title>地址信息</title> </head> <body> <h1>地址信息</h1><hr> <form action="step3.do" method="post"> 地址:<input type="text" name="address"/><br> <input type="submit" value="下一步"/> </form> </body> </html> |
finish.jsp
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <!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=GB18030"> <title>确认订单</title> </head> <body> <h1>确认订单</h1> <hr> <form action="finish.do" method="post"> 姓名:${stepForm.username }<br> 产品: <c:forEach items="${stepForm.productID}" var="p" varStatus="vs"> 产品${p } <c:if test="${vs.count != fn:length(stepForm.productID)}" var="v"> , </c:if> </c:forEach> <br> 地址:${stepForm.address }<br> <input type="submit" value="确认"> </form> </body> </html> |
2.StepActionForm.java
package com; import org.apache.struts.action.ActionForm; public class StepActionForm extends ActionForm { |
3.action
StartAction.java
package com; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.Action; public class StartAction extends Action { @Override |
Step1Action.java,Step2Action.java,Step3Action.java,FinishAction.java都相同
package com; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.Action; public class Step1Action extends Action { @Override |
3.struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE struts-config PUBLIC <struts-config> <action path="/step2" <action path="/step3" <action path="/finish" |