首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

struts2 ognl 输出 spring2.5 流入对象属性值

2012-10-08 
struts2 ognl 输出 spring2.5 注入对象属性值实验描述: 一、环境 1.spring2.5 管理 action 对象 2.struts2.

struts2 ognl 输出 spring2.5 注入对象属性值
实验描述:

一、环境

1.spring2.5 管理 action 对象

2.struts2.1.8管理转发 和 属性值输出

3.jboss4.0.2GA

4.开发工具 MyEclipse 8.5(除了开启有点慢!比开机都慢!其他的都不错!)


二、程序流程:

1. success.jsp :struts 表单 name 文本输入 提交 ac1.action处理

2.ac1.action :struts 的action类 并通过 spring 管理 注入Ac2.class 并Ac2.address属性赋值

3.返回到success.jsp 通过 ognl 输出 name 属性名 和Ac2.address属性 值


三、程序代码:

1.web.xml
<property name="ac2" ref="ac2"></property>
</bean>
<bean id="ac2" scope="prototype">
<property name="address" value="home"/>
</bean>
</beans>


3.struts.xml

<action name="action1" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">   
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

  </head>
 
  <body>
  <s:form action="action1">
  <s:textfield name="name" label="usename"></s:textfield>
  <s:submit value="提交"></s:submit>
  </s:form>
     <br>
     <s:property value="name"/>
     <s:property value="ac2.getAddress()"/>
     <s:debug></s:debug>
    
  </body>
</html>

6.发布
通过MyEclipse 发布到jboss
在地址栏输入:
http://localhost:8080/testss/success.jsp
出入:name 点击 提交
输出结果:
name home

呵呵就这些了 很简单,主要是试验一线 ognl 输出的注入对象的方法

热点排行