通过struts.xml搭建、为属性注入值_2015.01.04
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的更多相关文章
- struts几个配置文件加载顺序_2015.01.04
struts几个配置文件加载顺序: 01:struts-default.xml 02:struts-plugin.xml 03:struts.xml 04:struts.properties 05:w ...
- struts2视频学习笔记 07-08(为Action的属性注入值,指定需要Struts 2处理的请求后缀,常用常量)
课时7 为Action的属性注入值(增加灵活性,适用于经常更改的参数) Struts2为Action中的属性提供了依赖注入功能,在struts2的配置文件中,我们可以很方便地为Action中的属性注入 ...
- struts2_4_为Action属性注入值
Struts2为Action中的属性提供了依赖注入功能,在struts2的配置文件里,能够为Action中的属性注入值,属性必须提供setter方法. 1)employeeAction类: publi ...
- Spring 中IOC(控制反转)&& 通过SET方式为属性注入值 && Spring表达式
### 1. Spring IoC IoC:Inversion of control:控制反转:在传统开发模式下,对象的创建过程和管理过程都是由开发者通过Java程序来实现的,操作权在开发者的Java ...
- 05. struts2中为Action属性注入值
概述 struts2为Action中的属性提供了依赖注入功能 在struts2的配置文件中,我们可以很方便地为Action中的属性注入值.注意:属性必须提供get,set方法. 配置 <acti ...
- spring的基于XML方式的属性注入
1.掌握spring的属性注入的方法: 1.1构造方法注入普通值---------<constructor-arg>标签的使用 首先新建一个类 package spring.day1.de ...
- 配置文件Struts.xml 中type属性 redirect,redirectAction,chain的区别
1.redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失. 2.redirectAction:action处理完后重定向到一 ...
- Spring为某个属性注入值或为某个方法的返回值
项目中用到需要初始化一些数据,Spring提供了filed的值注入和method的返回值注入. 一.Field值的注入 filed值注入需要使用org.springframework.beans.fa ...
- struts2配置文件(struts.xml)中相关属性的设置
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-/ ...
随机推荐
- 回调的代理(delegate)实现
1.CoreManage.h #import <Foundation/Foundation.h> @protocol SampleProtocol; //声明核心类的属性和方法 @inte ...
- mysql源码重启
1.通过rpm包安装的MySQL service mysqld restart /etc/inint.d/mysqld start 2.从源码包安装的MySQL // linux关闭MySQL的命令 ...
- 用angularJS实现Bootstrap的“手风琴”
主页面代码(发现Bootstrap官网上手风琴的实例样式有问题,在这里依然使用3.0.~版本) <!DOCTYPE html> <html ng-app="ct" ...
- 让Dreamweaver支持less
编辑->首选参数->文件类型/编辑器->在代码视图中打开->添加" .less"后缀
- caption,为表格增加标题和摘要
格式: <table summary="***"> <caption>***</caption> <tr> </tr> ...
- javac 错误: 编码GBK的不可映射字符
在java代码中有中文注释,使用javac编译时,出现编码报错. 错误: 编码GBK的不可映射字符 问题原因: 在编译的时候,如果我们没有用-encoding参数指定我们的JAVA源程序的编码格式,则 ...
- imx6 MFG TOOL 分析
之前分析过mfgtool的内容,最近从官网下载,返现新版的mfgtool工具将imx6各种版本的linux/android都使用一个工具进行烧录.所以从新分析一下. 新版与旧版的一个区别是烧写使用的u ...
- LeetCode H-Index II
原题链接在这里:https://leetcode.com/problems/h-index-ii/ 题目: Follow up for H-Index: What if the citations a ...
- jQuery判断某个元素是否存在某个样式
<input type="button" class="new"/> $("input[name=new]").hasClass ...
- UR fall detection dataset
http://fenix.univ.rzeszow.pl/~mkepski/ds/uf.html