- 浏览: 151221 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
hx0637:
楼主!小弟要面临面试了,能否指导下小弟?
面试 深圳一家公司的 -
kljismi:
你好,我现在正在开这项目的代码,但是我不明白@Privileg ...
权限管理模块分析 -
yzhw:
终于找到了
ImageSizer.java -
sunloveny:
国
struts国际化 -
jackotty:
谢谢楼主的分享
struts validator验证框架
StartAction.java
Step1Action.java
Step2Action.java
Step3Action.java
FinishAction.java
StepActionForm.java
struts-config.xml
index.jsp
step1.jsp
step2.jsp
step3.jsp
finish.jsp
success.jsp
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>
发表评论
-
drp_user
2009-01-11 15:10 1189采用DispathAction * 如果覆写DispathA ... -
编程式异常 -声明式异常
2009-01-11 11:28 14781、编程式异常 * 截获异常 * 创建相应的异常消息 * ... -
struts validator验证框架
2009-01-07 23:35 2902struts validator验证框架 1、配置: * ... -
struts国际化
2009-01-07 23:18 66631、struts国际化的配置 * 在struts-confi ... -
了解Locale
2009-01-07 23:01 12721、了解缺省Locale是由操作系统决定的,Locale是由语 ... -
actionmapping
2009-01-07 22:48 14091、struts-config.xml文件中,每个<ac ... -
ActionForward的使用
2009-01-07 22:13 41991、理解全局和局部ActionForward的概念 2、red ... -
ActionForm
2009-01-07 20:06 14971、动态ActionForm 动态ActionForm是为了 ... -
DispatchAction.java
2009-01-07 19:48 1076/* * $Id: DispatchAction.java ... -
模式匹配
2009-01-07 19:41 779UserAction.java package com. ... -
jstl标签库的配置
2009-01-07 18:51 3412jstl标签库的配置 * 将jstl.jar和standar ... -
1.2.9 RequestProcessor.java
2008-12-27 17:47 1301/* * $Id: RequestProcessor.ja ... -
1.2.9 ActionServlet.java
2008-12-27 17:43 1206/* * $Id: ActionServlet.java ... -
struts_login
2008-12-27 17:32 9071、配置struts * 拷贝struts lib下的所有j ... -
struts_trainnig_cal
2008-12-26 23:17 666CalAction.java package com.bj ... -
bjsxt test_servlet
2008-12-26 22:46 1126TestServlet.java package com. ...
相关推荐
标题“ActionForm_Scope为Session”涉及到的是Struts框架中的一个关键概念,即ActionForm对象的作用域设置。在Struts框架中,ActionForm是用于封装请求参数并传递给业务逻辑层(通常为Servelets或JavaBeans)的模型...
【ActionForm】是Java Web开发中的一个概念,主要在Struts框架中被广泛使用。它是一种模型层对象,用于接收用户从视图层(通常是一个HTML表单)传递过来的数据,并将这些数据转发到控制器(Controller)进行业务逻辑...
ActionForm可以在request、session或application作用域中使用。在request作用域中,ActionForm实例会被创建和销毁;在session作用域中,ActionForm实例会被多个请求共享。 5. ActionForm的优点 使用ActionForm可以...
ActionForm是Struts框架的核心组件之一,它主要用于收集用户在表单中的输入数据,并将这些数据传递到Action类进行业务逻辑处理。 首先,我们需要理解ActionForm的作用。在用户提交一个HTML表单后,Struts框架会创建...
ActionForm是Struts框架中的一个核心组件,它负责收集和验证来自客户端的数据。在本例中,`userform`继承自`ActionForm`,并且包含了一个`userEntity`实例。这表明`userform`不仅承担了表单数据的封装任务,还能直接...
本集成开发宝典主要关注如何将这三者有效地结合,以ActionForm为切入点,深入讲解它们的整合过程。 Struts 是一个基于MVC(Model-View-Controller)设计模式的Web应用框架,它主要用于控制应用的流程,处理用户请求...
4. **scope**: `scope`属性指定`ActionForm`对象的生存周期,可以是`request`或`session`。`request`意味着`ActionForm`只在当前HTTP请求内有效,而`session`则使其在用户整个会话期间有效。 5. **type**: `type`...
- `session`范围的ActionForm在整个会话期间有效,适用于需要跨页面保持状态的情况。 - `prototype`范围的ActionForm每次请求都会创建新的实例,适用于复杂的业务逻辑。 5. **Struts 2的改进** - 在Struts 2中,...
ActionForm是Struts框架中一个关键的组件,它充当了Controller与Model之间的桥梁,负责传递用户在表单中提交的数据到业务逻辑层。本篇文章将深入探讨ActionForm中的get和set方法及其作用。 1. **ActionForm基础** ...
ActionForm是Struts1中处理用户输入的核心组件,它负责接收、验证和封装来自表单的数据。在本文中,我们将深入探讨如何利用ActionForm实现表单验证,并在验证失败时追加错误信息。 1. **ActionForm介绍** ...
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { RoleDAO dao = new RoleDAOImpl(); List<Role> list = ...
1. 创建:ActionForm实例可以在请求级别或者session级别被创建。请求级别意味着每个HTTP请求都会创建一个新的ActionForm实例,而session级别则表示一个用户的整个会话期间共享一个ActionForm。 2. 数据绑定:用户...
public ActionForward session(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println(...
上述代码中,`/login`是URL路径,`com.example.LoginAction`是处理登录请求的Action类,`scope="session"`表示将ActionForm对象保存在会话中,以便在多个请求之间共享数据。`success`和`error`是两种可能的转发结果...
在Struts 1中,ActionForm是MVC设计模式中的模型部分,它负责收集、验证和封装用户的输入数据,然后传递给Action类进行业务逻辑处理。 **ActionForm详解** ActionForm是Struts 1的核心组件之一,它是Servlet API中...
这里的`/login`是请求路径,`com.example.LoginAction`是Action类,`loginForm`是ActionForm的bean名,`scope="session"`表示ActionForm将存储在会话中。 接着,创建`LoginAction.java`,检查用户名和密码,如果...
在Struts中,ActionForm类是处理用户输入数据的核心组件,它封装了请求参数并负责业务逻辑验证。本文将详细讨论如何在Struts中使用ActionForm的`validate`方法进行数据验证。 `validate`方法是在ActionForm中定义的...
当我们需要在客户端提交多行数据时,通常会利用表单来收集信息,然后将这些数据传递到服务器端的ActionForm。这个过程涉及到如何将客户端的数据组织成一个集合,如List,并将其绑定到ActionForm的属性上。在本篇中,...
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { FileItemFactory factory = new ...
1. **ActionForm接口**:首先,你需要了解ActionForm的基本概念,它是Struts框架中一个实现了Servlet API的ActionForm接口的类,负责收集和验证来自HTML表单的数据。 2. **动态生成ActionForm**:在动态ActionForm...