一、开发环境:JDK6.0+MyEclipse6.0+TOMCAT6.0
二、准备jar包:这里用的是struts2-2.0.12版本,解压后,在lib中选出这个几个核心jar包即可。
commons-logging-api-1.1.jar , freemarker-2.3.8.jar ,ognl-2.6.11.jar,struts2-core-2.0.12.jar,xwork-2.0.6.jar
三、开发步骤:
1,在myeclipse中创建web项目,把准备好的几个核心jar包加入lib目录,在项目的web.xml文件中,配置struts2的核心控制器(FilterDispatcher过滤器)
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2,在src目录下,加入struts2的配置文件 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><!-- 该文件放到src目录下,编译后自动部署到classes目录 -->
</struts>
3,写Action,写Action时继承com.opensymphony.xwork2.ActionSupport 即可
package sample1;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public String execute() {
name = "hello," + name + "!";
return "ok";//下一步跳转标记
}
}
4,在struts.xml中配置写好的action ,确定跳转页面
<?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><!-- 该文件放到src目录下,编译后自动部署到classes目录 -->
<package name="" extends="struts-default">
<action name="hello" class="sample1.HelloWorldAction">
<result name="ok">showHello.jsp</result><!-- 执行后跳转页面 -->
</action>
</package>
</struts>
5,写对应的跳转页面showHello.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %><!-- 引入struts2标签 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>showHello</title>
</head>
<body>
<s:property value="name"/><!-- 使用struts2标签输出name属性值,通过反射调用getName() -->
</body>
</html>
四、部署项目到tomcat,启动运行
在浏览器输入地址:http://localhost:8888/app/hello.action?name=lekihuo 即可得到HelloWorldAction中的name属性值
其中hello为在struts.xml中配置action的name
分享到:
相关推荐
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,...
新建maven工程,对于Struts2入门单纯使用案例HelloWorld
NULL 博文链接:https://huangminwen.iteye.com/blog/1827985
-- 为修复struts2 s2-016、s2-017漏洞,重写DefaultActionMapper --> <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="myDefaultActionMapper" class=...
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框架的核心类库,以及Struts2的第三方插件类库 struts2-core-2.0.14 xwork-2.0.7 ognl-2.6.11 commons-logging-1.0.4 freemarker-2.3.8 等等。
2017年7月7日,Apache Struts发布最新的安全公告,Apache Struts2-strus1-plugin插件存在远程代码执行的高危漏洞,漏洞编号为CVE-2017-9791(S2-048),主要受影响的Struts版本为:2.3.x。 攻击者可以构造恶意的字段值...
struts2-struts1-plugin-2.3.30.jar, struts2-testng-plugin-2.3.30.jar, struts2-tiles-plugin-2.3.30.jar, struts2-tiles3-plugin-2.3.30.jar, tiles-api-2.2.2.jar, tiles-compat-3.0.1.jar, tiles-core-2.2.2....
struts-taglib-1.3.8.jar struts-taglib-1.3.8.jar
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-json-plugin,Struts JSON插件
包含struts2-core-2.5.10.1.jar,struts2-jfreechart-plugin-2.5.10.1.jar,struts2-json-plugin-2.5.10.1.jar,struts2-junit-plugin-2.5.10.1.jar,struts2-bean-validation-plugin-2.5.10.1.jar,struts2-cdi-...
Struts入门--按步骤一步步来就可以了 从网上搜了2个例子,感觉不错,所以共享出来,给入门者使用
struts2.0开发环境的搭建及HelloWorld的演示
struts2-ssl-plugin-1.2.1.jar
struts2-bean-validation-plugin-2.5.2.jar, struts2-cdi-plugin-2.5.2.jar, struts2-config-browser-plugin-2.5.2.jar, struts2-convention-plugin-2.5.2.jar, struts2-core-2.5.2.jar, struts2-dwr-plugin-2.5.2....
NULL 博文链接:https://mbi325.iteye.com/blog/255056
jquery和struts2结合使用的jar包
【Struts2】〖所有依赖jar包〗struts-2.3.37-lib 我寻见一片海 碧蓝且耀着光 大片船只航行其上 都向着远方 Shared by Foriver_江河 © 1997-8023 江河 All Rights Reserved.
struts2-convention-plugin-2.3.32