`

struts1.x 对应的配置文件

阅读更多

1.在web.xml中添加Servlet

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
	xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>strutsOne</display-name>

	<servlet>
		<servlet-name>action</servlet-name>
		<servlet-class>
			org.apache.struts.action.ActionServlet
		</servlet-class>
              <!--default struts-config.xml fileContext-->
		<init-param>
			<param-name>config</param-name>
			<param-value>/WEB-INF/struts-config.xml</param-value>
		</init-param>
              <!--node config 下的usb 指的是对应的path添加值相当于
                 struts2 中的namespace="/usb"-->
		<init-param>
			<param-name>config/usb</param-name>
			<param-value>
				/WEB-INF/systemset/struts-config.xml
			</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
	    <servlet-name>action</servlet-name>
	    <url-pattern>*.do</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>

 2 对应API

public abstract class DispatchActionextends BaseAction
An abstract Action that dispatches to a public method that is named by the request parameter whose name is specified by the parameter property of the corresponding ActionMapping. This Action is useful for developers who prefer to combine many similar actions into a single Action class, in order to simplify their application design.

To configure the use of this action in your struts-config.xml file, create an entry like this:

<action path="/saveSubscription" type="org.apache.struts.actions.DispatchAction" name="subscriptionForm" scope="request" input="/subscription.jsp" parameter="method"/> 
which will use the value of the request parameter named "method" to pick the appropriate "execute" method, which must have the same signature (other than method name) of the standard Action.execute method. For example, you might have the following three methods in the same action:

public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 
public ActionForward insert(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 
public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 
and call one of the methods with a URL like this:

http://localhost:8080/myapp/saveSubscription.do?method=update 

   Node:/WEB-INF/systemset/struts-config.xml

            /WEB-INF/struts-config.xml

  3.JAVA Action 类

 

package com.helloworld.action;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class HelloWorldAction extends DispatchAction {

	
	public ActionForward sayHelloWorld(ActionMapping actionMapping, ActionForm actionForm,
	HttpServletRequest request, HttpServletResponse response) throws Exception {
		System.out.println("HelloWorld........");
		
		request.setAttribute("say", "Hello World My Struts 1.3.x");
		return actionMapping.findForward("say");
	}
	
	public ActionForward us(ActionMapping actionMapping, ActionForm actionForm,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
				System.out.println("HelloWorld........");
				
				request.setAttribute("say", "Hello World Struts1.3.x namespace configuretion ");
				return actionMapping.findForward("us");
			}

}
分享到:
评论

相关推荐

    Struts1.x常用的开发包,需要学习struts1.x朋友可以下载

    3. **配置文件**:Struts1.x的配置主要分为两个部分:struts-config.xml和web.xml。struts-config.xml定义了Action的映射、Form Beans、数据源、以及其他的配置项。web.xml则配置了Struts Filter和Servlet。 4. **...

    Struts1.x系列教程(网摘-全)

    6. **ActionServlet**:作为Struts1.x的入口点,负责解析请求,根据配置文件调用对应的Action。它是一个扩展了Servlet的类,处理HTTP请求。 7. **RequestProcessor**:在ActionServlet之后处理请求,它是Struts1.x...

    java Struts 1.x 框架 Web 开发

    3. **配置文件**:Struts 配置文件(struts-config.xml)定义了Action的映射、数据源、国际化资源、表单 Beans 等。它是Struts应用的核心配置,指导框架如何处理请求和响应。 4. **ActionForm**:ActionForm 类用于...

    struts1.x入门教程

    在Struts1.x中,Controller由ActionServlet实现,它处理HTTP请求,并通过配置文件(struts-config.xml)调度Action类来执行特定的业务逻辑。 接下来,我们将逐步了解如何创建一个简单的Struts1.x应用: 1. **搭建...

    Struts1.x的登录示例

    通过这个简单的Struts1.x登录示例,你可以了解Struts1.x的MVC工作流程、配置文件的编写以及Action和ActionForm的使用。然而,需要注意的是,Struts1.x已经较为过时,现代的Web开发更多地转向了Spring MVC、Play ...

    Struts1.x_Project.zip

    5. **Struts-config.xml**:配置文件,包含了ActionMapping、ActionForm、数据源等设置。 **I18N国际化:** 在Struts1.x中,实现I18N(Internationalization)主要是通过资源文件(如*.properties)来管理不同语言...

    struts1.x 最简洁国际化 源代码

    5. **配置文件**: - 在`struts-config.xml`中,可以通过`message-resources`元素指定资源包的位置和加载策略。例如: ```xml &lt;message-resources parameter="com.example.myapp.ApplicationResources" /&gt; ``` ...

    struts2.x所有包及配置文件

    这个压缩包"struts2.x所有包及配置文件"包含了Struts2框架的核心组件、扩展和配置文件,用于构建和管理Java web应用。 1. **核心组件**: - `struts2-core.jar`:这是Struts2框架的基础,包含了Action、Result、...

    Struts1.x的上传文件示例

    首先,你需要在Struts的配置文件(struts-config.xml)中定义一个Action,这个Action将会处理文件上传请求。你可能需要创建一个新的Action类,继承自Struts的基础Action类,并重写execute方法来处理上传请求。 ```...

    Struts1.x.rar

    3. **配置文件**:Struts1.x的核心配置文件是struts-config.xml,它定义了ActionMapping,ActionForm,以及ActionServlet如何处理请求。在购物网项目中,我们需要在此文件中配置不同的Action,对应不同的购物功能,...

    Struts1.x在线购物车系统,Hibernate,Mysql

    Struts1.x 提供了一系列的拦截器(Interceptor)和动作(Action)来处理用户请求,并通过配置文件(struts-config.xml)来定义这些请求的映射关系。在这个购物车系统中,Struts1.x 负责接收用户的HTTP请求,调用相应...

    Struts1.x_action

    总的来说,Struts1.x_action这个资源包可能包含了一些预配置的Action类、ActionForm类、配置文件示例以及相关的JSP页面,帮助开发者快速搭建一个基于Struts1.x的Web应用。使用这个包,开发者可以直接导入项目,然后...

    struts1.x 上传下载

    1. **配置**: 首先,需要在`struts-config.xml`配置文件中添加`controller`配置,启用MultipartRequestHandler。 ```xml &lt;controller processorClass="org.apache.struts.upload.MultipartRequestHandler" /&gt; ``` 2....

    Struts1.x-Jdbc,学习Struts1.的曾删改查

    - **配置文件**:`struts-config.xml`是Struts1的配置文件,定义了Action类和ActionForm对象,以及URL到Action的映射。 - **ActionForm**:用于接收并封装来自客户端的表单数据,然后传递给Action处理。 2. **...

    struts1.x 常用知识详解

    3. **配置文件**:`struts-config.xml`是Struts1.x的核心配置文件,用于定义Action、ActionForm、ActionForward等元素,以及数据源和国际化资源等。 二、ActionForm与数据绑定 1. **ActionForm**:ActionForm对象...

    struts1.x整合freemarker

    - **配置Freemarker**: 首先,在Struts1.x的配置文件(struts-config.xml)中添加Freemarker的配置,包括模板目录设置、编码设置等。 - **Action类改造**: 将原本在JSP中使用的EL表达式和JSTL标签替换为Freemarker...

    struts1.x 和 struts2.x向Action里填充jsp参数原理

    然后,ActionServlet根据配置文件(struts-config.xml)找到对应的Action类,并将ActionForm中的数据传入Action类,执行业务逻辑。最后,Action返回一个ActionForward对象,Dispatcher根据这个对象决定转发到哪个JSP...

    struts1.x实现的网上书店示例

    2. **配置文件(struts-config.xml)**:这是Struts1.x的核心配置文件,它定义了Action的映射、Form Bean的配置以及结果页面的跳转规则。例如,你可以在这里指定哪个URL请求应该由哪个Action处理。 3. **Form Bean**...

    Struts2.X+Hibernate3.X+Spring2.5 整合

    Struts2的配置文件(struts.xml)通常用来定义Action类及其对应的视图,以及全局的拦截器等。Hibernate的配置文件(hibernate.cfg.xml)用于设置数据库连接参数,实体类需要通过注解或XML映射文件与数据库表进行关联...

    struts1.x和mysql整合的登陆例子

    Struts1.x是一个经典的MVC(Model-View-Controller)框架,它在Java Web开发中广泛应用,尤其是在2000年代中期。这个框架为开发者提供了一种组织和控制应用程序逻辑的方式,使得前端与后端数据处理分离,提高了代码...

Global site tag (gtag.js) - Google Analytics