分步收集,ActionForm的scope=session

StartAction.java

package com.bjsxt.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class StartAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
StepActionForm saf = (StepActionForm)form;
saf.resetField();
return mapping.findForward("success");
}
}


Step1Action.java

package com.bjsxt.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class Step1Action extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("success");
}
}


Step2Action.java


package com.bjsxt.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class Step2Action extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("success");
}
}



Step3Action.java

package com.bjsxt.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class Step3Action extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("success");
}
}



FinishAction.java

package com.bjsxt.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class FinishAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("success");
}
}


StepActionForm.java


package com.bjsxt.struts;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class StepActionForm extends ActionForm {


private String name;

private int[] productId;

private String address;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int[] getProductId() {
return productId;
}

public void setProductId(int[] productId) {
this.productId = productId;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

// public void reset(ActionMapping mapping, HttpServletRequest request) {
// this.name = null;
// this.productId = null;
// this.address = null;
// }

public void resetField() {
this.name = null;
this.productId = null;
this.address = null;
}
}



struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>

<form-beans>
<form-bean name="stepForm" type="com.bjsxt.struts.StepActionForm"/>
</form-beans>

<action-mappings>
<action path="/start"
type="com.bjsxt.struts.StartAction"
name="stepForm"
scope="session"
>
<forward name="success" path="/step1.jsp"/>
</action>

<action path="/step1"
type="com.bjsxt.struts.Step1Action"
name="stepForm"
scope="session"
>
<forward name="success" path="/step2.jsp"/>
</action>

<action path="/step2"
type="com.bjsxt.struts.Step2Action"
name="stepForm"
scope="session"
>
<forward name="success" path="/step3.jsp"/>
</action>

<action path="/step3"
type="com.bjsxt.struts.Step3Action"
name="stepForm"
scope="session"
>
<forward name="success" path="/finish.jsp"/>
</action>

<action path="/finish"
type="com.bjsxt.struts.FinishAction"
name="stepForm"
scope="session"
>
<forward name="success" path="/success.jsp"/>
</action>

</action-mappings>
</struts-config>



index.jsp


<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
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="<%=basePath%>">

<title>My JSP 'index.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<h1>分步收集</h1>
<hr>
<a href="start.do">分步收集</a>
</body>
</html>


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="name"><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>
<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.name }<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>



success.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>Insert title here</title>
</head>
<body>
购物成功!
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值