struts标签是为了减少代码量,而是用的一种方便快捷的输出方式;这次是struts1.x版本;
1:首先搭建好的struts1.x的环境;
2:在示例程序中的struts-config.xml找到<message-resources parameter="MessageResources" />放到struts-config.xml中;
3:在java目录下找到MessageResources.properties并拷贝到src目录下;
下面看代码理解:
BeanwriteTest.java:
package com.keith;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class BeanWriteTest extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//普通属性
request.setAttribute("hello", "hello struts_taglibs");
//html文本
request.setAttribute("man","<font color='red'>keith</font>");
//日期
request.setAttribute("date",new Date());
//数字
request.setAttribute("n",124578.454);
//结构
Group group = new Group();
group.setGroupName("keithClass");
User user = new User();
user.setName("keith");
user.setAge(20);
user.setGroup(group);
request.setAttribute("user",user);
return mapping.findForward("beanwriteSuc");
}
}
由于用到了的结构:
user.java:
package com.keith;
public class User {
private String name;
private int age;
private Group group;
public Group getGroup() {
return group;
}
public void setGroup(Group group) {
this.group = group;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
Group.java:
package com.keith;
public class Group {
private String groupName;
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
}
struts-config.xml中:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<action-mappings>
<action path="/beanWritetest"
type="com.keith.BeanWriteTest"
>
<forward name="beanwriteSuc" path="/beanwrite.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
beanwrite.jsp:首先要在jsp页面中使用struts标签的话,需要加入:
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
这句话是设定struts的位置及版本,在struts.jar/META-INF/tlds的目录下可以找到;
下面是<body></body>中的代码:
<h2>测试beanwrite</h2>
<hr color="orange" size="4"><br>
hello(jsp脚本):<%= request.getAttribute("hello") %><br>
hello(标签):<bean:write name="hello"/><p></p>
html文本:<br>
man(default):<bean:write name="man"/><!-- 原样输出了 --><br>
man(filter=false):<bean:write name="man" filter="flase"/><p></p>
日期(default):<bean:write name="date"/><br>
日期(format="yyyy-MM-dd HH:mm:ss"):<bean:write name="date" format="yyyy-MM-dd HH:mm:ss"/><p></p>
数字(default):<bean:write name="n"/><br>
数字(format="###,###.#"):<bean:write name="n" format="###,###.#"/><br>
数字(format="###,###.#"):<bean:write name="n" format="###,###.00000"/><p></p>
结构:<br>
姓名:<input type="text" value="<bean:write name="user" property="name"/>"><!-- property="name" 相当于调用了user.getName()方法,标签是在服务器端执行 --> <br>
年龄:<input type="text" value="<bean:write name="user" property="age"/>"> <br>
所属组:<input type="text" value="<bean:write name="user" property="group.groupName"/>"> <br>
在index.jsp中给个请求:
<a href="beanWritetest.do">测试beanWritetest</a>
分享到:
相关推荐
struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...
标签:apache、struts2、plugin、struts、json、jar包、java、API文档、中文版; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,...
struts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jarstruts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jar
Struts2-showcase是一个用于演示和学习Apache Struts2框架功能的开源项目。这个压缩包“struts2-showcase.rar”包含了完整的源代码,旨在帮助开发者深入理解Struts2框架的工作原理及其各种特性。以下是对Struts2和...
struts2-config-browser-plugin-2.3.24.jar, struts2-core-2.3.24.jar, struts2-jasperreports-plugin-2.3.24.jar, struts2-jfreechart-plugin-2.3.24.jar, struts2-pell-multipart-plugin-2.3.24.jar, struts2-...
struts2-struts1-plugin-2.1.6.jar
struts2-ssl-plugin-1.2.1.jar
struts2-json-plugin,Struts JSON插件
struts2-core-2.2.3.1-sources.jar struts2-core-2.2.3.1-sources.jar struts2-core-2.2.3.1-sources.jar
Struts2-Spring-Plugin-2.3.4.jar 是一个专门为 Struts 2 框架和 Spring 框架整合而设计的插件,主要用于处理 Struts 2 和 Spring 之间的集成问题。在Java Web开发中,这两个框架经常一起使用,Spring 提供了依赖...
`struts2-json-plugin-2.1.8.1.jar` 则是Struts 2框架的一个插件,主要用于增强Struts 2对JSON的支持。Struts 2是一款非常流行的MVC(Model-View-Controller)框架,用于构建企业级的Java Web应用程序。这个插件允许...
struts2-core-2.5.18.jar包下载,支持struts2的类库下载
最新struts2-struts1-plugin-2.1.8.1.jar
一旦配置完成,你就可以在JSP页面上直接使用Dojo的标签库,例如`<s:dojo>`和`<s:dojotheme>`,来创建和管理Dojo元素。 在实际开发中,你可能需要学习和理解以下几点: 1. Dojo的模块化系统(AMD,Asynchronous ...
struts2-showcase.war
struts2-dojo 跨域时解决拒绝访问的问题
struts2-json-plugin-2.3.15.1 -Lee修复bug版.jarstruts2-json-plugin-2.3.15.1 -Lee修复bug版.jarstruts2-json-plugin-2.3.15.1 -Lee修复bug版.jarstruts2-json-plugin-2.3.15.1 -Lee修复bug版.jar
struts2-convention-plugin-2.3.24.1
struts2-convention-plugin-2.3.15.1.jar
struts2-plexus-plugin-2.1.6.jar