01:web.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"> <!-- 01:启动struts2框架 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

02:编写action类

package com.self.action;
/**
* 02:写相应的处理方法
*/
public class HelloWorldAction { private String message; public String dohelloworld(){
return "doresult";
} //为属性注入值,需要提供set方法
public void setMessage(String message) {
this.message = message;
}
//在页面显示值,需要get方法
public String getMessage() {
return message;
} }

03:配置struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts>
<!-- o3:配置相应的类、方法 -->
<package name="hw" namespace="/test" extends="struts-default">
<action name="helloworld" class="com.self.action.HelloWorldAction" method="dohelloworld">
<!-- 为属性注入值 -->
<param name="message">in_message</param>

<result name="doresult">
/showresult.jsp
</result>
</action>
</package>
</struts>

04:页面获取值:

  <!-- 第4步:显示 -->
<body><BR><br><BR>
<center>
将页面放在WEB-INF下面,这样用户直接访问不到<BR><br> 为action的属性注入值:
${message}
<BR></center>
</body>

通过struts.xml搭建、为属性注入值_2015.01.04的更多相关文章

  1. struts几个配置文件加载顺序_2015.01.04

    struts几个配置文件加载顺序: 01:struts-default.xml 02:struts-plugin.xml 03:struts.xml 04:struts.properties 05:w ...

  2. struts2视频学习笔记 07-08(为Action的属性注入值,指定需要Struts 2处理的请求后缀,常用常量)

    课时7 为Action的属性注入值(增加灵活性,适用于经常更改的参数) Struts2为Action中的属性提供了依赖注入功能,在struts2的配置文件中,我们可以很方便地为Action中的属性注入 ...

  3. struts2_4_为Action属性注入值

    Struts2为Action中的属性提供了依赖注入功能,在struts2的配置文件里,能够为Action中的属性注入值,属性必须提供setter方法. 1)employeeAction类: publi ...

  4. Spring 中IOC(控制反转)&& 通过SET方式为属性注入值 && Spring表达式

    ### 1. Spring IoC IoC:Inversion of control:控制反转:在传统开发模式下,对象的创建过程和管理过程都是由开发者通过Java程序来实现的,操作权在开发者的Java ...

  5. 05. struts2中为Action属性注入值

    概述 struts2为Action中的属性提供了依赖注入功能 在struts2的配置文件中,我们可以很方便地为Action中的属性注入值.注意:属性必须提供get,set方法. 配置 <acti ...

  6. spring的基于XML方式的属性注入

    1.掌握spring的属性注入的方法: 1.1构造方法注入普通值---------<constructor-arg>标签的使用 首先新建一个类 package spring.day1.de ...

  7. 配置文件Struts.xml 中type属性 redirect,redirectAction,chain的区别

    1.redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失.  2.redirectAction:action处理完后重定向到一 ...

  8. Spring为某个属性注入值或为某个方法的返回值

    项目中用到需要初始化一些数据,Spring提供了filed的值注入和method的返回值注入. 一.Field值的注入 filed值注入需要使用org.springframework.beans.fa ...

  9. struts2配置文件(struts.xml)中相关属性的设置

    <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-/ ...

随机推荐

  1. 蓝牙4.0的LM层说明

    1.概念 The Link Manager Protocol (LMP) is used to control and negotiate all aspects of the operation o ...

  2. graphviz - Node Shapes

    Node Shapes There are three main types of shapes : polygon-based, record-based and user-defined. The ...

  3. Spark Programming--Actions

    first def first(): T first返回RDD中的第一个元素,不排序. 例子: count def count(): Long count返回RDD中的元素数量 例子: reduce ...

  4. Be a Smart Project Manager

    The key to being a smart project manager is to remember how you are going to manage your project, to ...

  5. DHT(Distributed Hash Table) Translator

    DHT(Distributed Hash Table) Translator What is DHT? DHT is the real core of how GlusterFS aggregates ...

  6. iOS Plist文件,增删改查

    今天早上,9点开始弄Plist,然后一直写,一直写(中午取出40分钟吃饭时间),写到1点,写完了,交给头,头说,不是这个意思.我是每个用户创建了一个文件夹,在这个用户的文件夹里面,分别根据应用创建了文 ...

  7. JVM底层又是如何实现synchronized的

    目前在Java中存在两种锁机制:synchronized和Lock,Lock接口及其实现类是JDK5增加的内容,其作者是大名鼎鼎的并发专家Doug Lea.本文并不比较synchronized与Loc ...

  8. POJ1528问题解答

    #include <iostream>#include <cstdio>#include <cmath> #include <string>#inclu ...

  9. dd命令使用详解

    dd命令使用详解 http://www.cnblogs.com/qq78292959/archive/2012/02/23/2364760.html 1.命令简介 dd 的主要选项: 指定数字的地方若 ...

  10. iOS多线程知识总结--GCD

    iOS多线程知识总结--GCD 1. iOS中苹果提供4钟方案来帮助我们实现多线程: (1) 纯C语言的pthread,偏底层,需要程序员手动管理线程的生命周期,基本不用. (2) OC语言的NSTr ...