`
weigang.gao
  • 浏览: 482313 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

mapping.findForward("error")获取的是struts-config.xml配置文件里面<forward name="error">

 
阅读更多

平时编写代码都没注意到,感觉挺有意思,因此记录下。

struts1.3中Action里面的 mapping.findForward("error")获取的是struts-config.xml配置文件里面<forward name="error"></forward>

如下:error必须要在struts-config.xml中配置,否则forward = null。

Java代码:

public class LoginAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		UserForm userForm = (UserForm) form;
		//这个error必须要在struts-config.xml中配置,否则 mapping.findForward("error") 获取的为null
        ActionForward forward = mapping.findForward("error");
		return forward;
	}
}

 

 struts-config.xml配置文件,在对应的action下必须要配置 <forward name="error" ></forward>

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
          "http://struts.apache.org/dtds/struts-config_1_3.dtd">

<struts-config>
<form-beans>  
        <form-bean  
            name="userform"  
            type="com.hsp.form.UserForm"/>  
    </form-beans>  
  
    <action-mappings>  
        <action  
            path="/login"  
            type="com.hsp.action.LoginAction"  
            name="userform"  
            >
           <forward name="error" path="/error.jsp"></forward>         
        </action>  
    </action-mappings>  
  
</struts-config>

 

 

 

分享到:
评论

相关推荐

    实现Struts上传多个文件

    在Struts项目中,配置文件主要有两个:`web.xml` 和 `struts-config.xml`。 - **web.xml** ```xml &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web ...

    Struts1的开发过程

    这里的`&lt;param-value&gt;`指定了Struts的配置文件`struts-config.xml`的位置。 3. 配置`struts-config.xml`:这是Struts的核心配置文件,用于定义Action、Form Bean、Action Mapping等。一个简单的配置示例如下: ```...

    Struts1的一个小实例

    然后,我们需要创建一个`struts-config.xml`配置文件,用于定义Action、ActionForm和ActionForward等元素。例如,我们可能有一个简单的用户登录功能,可以这样配置: ```xml &lt;action path="/login" type=...

    struts1配置的demo

    首先,Struts1的核心配置文件是`struts-config.xml`,它定义了应用的行为、动作映射和结果页面。在这个demo中,`Struts1_MyCinema`可能包含了这个配置文件,我们可以在其中看到各个Action的定义,如Action类名、对应...

    struts1非常好的一个资料

    &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;2&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;action&lt;/servlet-name&gt; &lt;url-pattern&gt;*.do&lt;/url-...

    struts配置及实例

    &lt;forward name="error" path="/error.jsp"/&gt; &lt;/action&gt; &lt;/action-mappings&gt; ``` 3. **ActionMapping**:将URL映射到特定的Action。上述例子中,访问"/upload"路径会调用`UploadAction`。 4. **数据源配置**:...

    Struts开发配置详细说明(v1.0)

    &lt;forward name="error" path="/jsp/error.jsp"/&gt; &lt;/action&gt; ``` - **Form Beans**: 用于声明表单bean,这些bean通常用于在ActionForm和JSP之间传递数据。 ```xml &lt;form-beans&gt; &lt;form-bean name="exampleForm" ...

    struts1 用户登录(包含验证)

    3. **配置 Struts 配置文件**:在 `struts-config.xml` 文件中配置 Action 映射关系以及表单验证规则等。 #### 三、具体实现 ##### 1. 表单类 `LoginForm` 表单类是继承自 `ActionForm` 的子类,用于封装用户输入...

    Struts学习----Action 的配置和使用(源码学习)

    首先,Action配置主要在Struts配置文件(struts-config.xml)中进行。这个文件定义了应用程序的行为,包括Action的映射、结果页面的设定、数据校验规则等。在`&lt;struts-config&gt;`标签内,我们通常会看到`&lt;action&gt;`标签...

    struts实现简单登录

    &lt;forward name="error" path="/error.jsp"/&gt; &lt;/action&gt; &lt;/action-mappings&gt; &lt;form-beans&gt; &lt;form-bean name="loginForm" type="com.example.LoginForm"/&gt; &lt;/form-beans&gt; ``` 3. **创建Action和ActionForm**: ...

    Struts1框架的登陆demo

    3. **配置文件**: Struts1的配置文件(通常为struts-config.xml)定义了Action和ActionForm的映射关系,以及请求转发路径。在`struts-config.xml`中,我们需要添加以下配置: ```xml &lt;struts-config&gt; &lt;form-beans&gt;...

    struts1 多个文件上传

    然后,在Struts的配置文件(struts-config.xml)中添加对应的action配置: ```xml &lt;action path="/upload" type="com.example.UploadAction" name="uploadForm"&gt; &lt;forward name="success" path="/success.jsp"/&gt; ...

    Struts 文件上传

    然后,在Struts配置文件(struts-config.xml)中,我们需要定义一个Action来处理文件上传请求: ```xml &lt;action path="/uploadAction" type="com.example.UploadAction" parameter="uploadFile"&gt; &lt;forward name=...

    struts实现简单的登陆

    2. `struts-config.xml`:Struts 配置文件,定义Action及其对应的ActionForm、结果页面等。 3. Action 类:处理用户请求的Java类,通常继承自`org.apache.struts.action.Action`。 4. ActionForm 类:封装用户输入...

    struts国际化功能

    接着,为了使用这些资源文件,我们需要在Struts配置文件(struts-config.xml)中声明一个`&lt;message-resources&gt;`元素,指定资源文件的位置。例如: ```xml &lt;struts-config&gt; &lt;global-exceptions/&gt; &lt;global-forwards...

    使用struts1.x上传多个文件的一中方法

    接下来,我们需要配置Struts1.x的配置文件(struts-config.xml),声明一个Action来处理文件上传。这里我们创建一个名为`UploadAction`的类,并在配置文件中声明: ```xml &lt;action path="/upload" type=...

    Struts1异常处理

    2. **Struts-config.xml配置异常处理**:在框架配置文件中,`&lt;global-exceptions&gt;`标签用于定义全局异常处理规则。例如: ```xml &lt;global-exceptions&gt; &lt;exception key="error.generic" type="java.lang.Exception...

    struts1.3页面跳转问题

    在Struts1.3中,页面跳转是常见的需求,它涉及到Action类、配置文件(struts-config.xml)以及JSP页面间的交互。本篇文章将深入探讨Struts1.3中的页面跳转机制及其相关知识点。 首先,页面跳转在Struts1.3中有两种...

    Struts与struts2比较学习

    - **Struts**: 使用`struts-config.xml`文件进行配置。 ```xml &lt;struts-config&gt; &lt;form-beans&gt; &lt;form-bean name="loginForm" type="com.example.LoginForm"/&gt; &lt;/form-beans&gt; &lt;action-mappings&gt; &lt;action path...

    Struts上传,已经处理好乱码问题

    在`struts-config.xml`中,需要为文件上传的Action配置`&lt;form-beans&gt;`和`&lt;action&gt;`元素。例如,创建一个名为`uploadForm`的表单bean,并指定`enctype="multipart/form-data"`,以启用多部分上传。 ```xml &lt;form-...

Global site tag (gtag.js) - Google Analytics