通过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 "-/ ...
随机推荐
- composer 272解决
composer global require "fxp/composer-asset-plugin:~1.0.3" ...
- 使用dnspod进行简单的HTTP dns解析(防劫持)
https://www.dnspod.cn/httpdns/guide https://www.dnspod.cn/misc/D%2B免费版本接口说明.pdf 最简单的get接口去请求dnspod提供 ...
- [LeetCode] Jump Game II(贪婪算法)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- SQLSERVER 16进制与10进制转换
最近工控项目中遇到的16进制与10进制转换,在.NET中比较容易实现,在SQLSERVER中发现没有直接的转换,尤其是出现超出范围的long负数,即无符号64位整数在sqlserver中的存储.网上找 ...
- ASP.NET 开发笔记1
1.GirdView 动态添加列 PostBack 后 模板列中的控件丢失的问题 http://blackboy51.blog.163.com/blog/static/511359122011910 ...
- 关于Xib 需要注意的地方
当你需要写一个繁琐的界面但是又是静态页面时,很可能会用到xib [特例:创建继承于UIView的文件时,不带自动生成xib的勾选项,需要开发人员手动new一个同名的xib文件,在该xib文件右侧的cl ...
- centos 6.4 安装视频解码器
cd /etc/yum.repos.d/ wget http://mirrors.163.com/.help/CentOS6-Base-163.repo yum update rpm -Uhv htt ...
- JSONModel 遇见关键字为id或者description
像id.description这样的,都是系统自带的,要解析它,得特殊处理一下.我用的是JSONModel { "contentList": [ { "id": ...
- [转]获得 LayoutInflater 实例的三种方式
转自:http://www.cnblogs.com/androidez/archive/2013/07/01/3164729.html 获得 LayoutInflater 实例的三种方式 在实际开 ...
- 分享一个使用APICloud云数据库已上线的商城APP
本项目盈利模式依赖taobao模块实现淘宝闭环交易,发布销售淘宝联盟产品获取返佣.目前已在应用宝上线安卓版本,先上图. 源码在此: http://community.apicloud.com/bbs/ ...