一.环境准备
struts-2.3.4.1-all :下载地址:http://struts.apache.org/download.cgi#struts2341
二.工程配置
1. Eclipse:File-New-Dynamic Web project,新建一个工程【strutsDemo】
2. 将struts-2.3.4.1-all 解压,里面的lib文件夹中的以下jar文件
antlr-2.7.2.jar
aopalliance-1.0.jar
asm-3.3.jar
commons-beanutils-1.8.0.jar
commons-chain-1.2.jar
commons-collections-3.1.jar
commons-digester-2.0.jar
commons-fileupload-1.2.2.jar
commons-io-2.0.1.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.jar
commons-validator-1.3.1.jar
freemarker-2.3.19.jar
javassist-3.11.0.GA.jar
ognl-3.0.5.jar
struts2-core-2.3.4.1.jar
xstream-1.4.2.jar
xwork-core-2.3.4.1.jar
copy进刚刚创建的工程的WebContent\WEB-INF\lib里面,
之后在eclipse中右键该工程选择build Path,
在弹出窗口中选择第3选项卡libraries,
点击右侧的【Add Library】在弹出窗口中选择Web App libraries,将其引入。
三.struts2配置
1.struts2与struts1不同,使用filter作为整个框架的入口。在web.xml中加入以下语句
<!-- struts2 starter Filters -->
<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>
2.之后配置struts2自己的配置文件struts.xml,类似于struts1的struts-config.xml文件,不过因为加载方式的不同,这个文件存在于classpath中,即工程的src文件夹下。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="strutsdemo" extends="struts-default">
<action name="index">
<result>/index.jsp</result>
</action>
<action name="hello" class="struts2.example.action.HelloWorldAction" method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
3.在src中加入在配置中指定的类文件HelloWorldAction
package struts2.example.action;
import struts2.example.model.MessageStore;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorldAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = -1407265450788291203L;
private MessageStore messageStore;
public String execute() throws Exception {
messageStore = new MessageStore() ;
return SUCCESS;
}
public MessageStore getMessageStore() {
return messageStore;
}
public void setMessageStore(MessageStore messageStore) {
this.messageStore = messageStore;
}
}
以及MessageStore
package struts2.example.model;
public class MessageStore {
private String message;
public MessageStore() {
setMessage("Hello Struts User");
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
4.添加jsp文件
index.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Basic Struts 2 Application - Welcome</title>
</head>
<body>
<h1>Welcome To Struts 2!</h1>
<p><a href="<s:url action='hello'/>">Hello World</a></p>
</body>
</html>
Helloworld.jsp
pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hello World!</title>
</head>
<body>
<h2><s:property value="messageStore.message" /></h2>
</body>
</html>
四.运行
总结:这个例子主要还是参照struts2的官方文档做的。
http://struts.apache.org/2.3.4.1/docs/guides.html
今后还会参照这个文档做些更复杂的例子。
另外发现struts通过convention-plugin实现了对annotation的支持,具体的内容请参照
http://struts.apache.org/2.3.4.1/docs/convention-plugin.html
分享到:
相关推荐
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,...
-- 为修复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
2017年7月7日,Apache Struts发布最新的安全公告,Apache Struts2-strus1-plugin插件存在远程代码执行的高危漏洞,漏洞编号为CVE-2017-9791(S2-048),主要受影响的Struts版本为:2.3.x。 攻击者可以构造恶意的字段值...
struts-core-1.3.10.jar, struts2-cdi-plugin-2.3.30.jar, struts2-codebehind-plugin-2.3.30.jar, struts2-config-browser-plugin-2.3.30.jar, struts2-convention-plugin-2.3.30.jar, struts2-core-2.3.30.jar, ...
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 s2-045
赠送jar包:struts2-json-plugin-2.3.24.jar; 赠送原API文档:struts2-json-plugin-2.3.24-javadoc.jar; 赠送源代码:struts2-json-plugin-2.3.24-sources.jar; 赠送Maven依赖信息文件:struts2-json-plugin-...
struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-...
struts2-json-plugin,Struts JSON插件
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....
struts2-ssl-plugin-1.2.1.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 等等。
【Struts2】〖所有依赖jar包〗struts-2.3.37-lib 我寻见一片海 碧蓝且耀着光 大片船只航行其上 都向着远方 Shared by Foriver_江河 © 1997-8023 江河 All Rights Reserved.
struts2-dojo-plugin-2.3.4 jar 日期控件的jar包 需要的自行下载
包含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-...
struts2-jquery-plugin-3.1.0.jar
struts2-convention-plugin-2.3.32
struts-2.3.34-all.rar,包括app,docs,lib,src