Struts2:
本质上相当于一个servlet,在MVC设计模式中,Struts2作为控制器(Controller)来建立模型与视图的数据交互。
但近日,安全研究人员发现著名J2EE框架--Struts2存在远程代码执行的漏洞,Struts2官方官方已经确认该漏洞(S2-046),CVE编号为:CVE-2017-5638,风险等级为高危漏洞。所以近年一般使用Struts使用框架进行老项目的维护工作。
1.导包(不能将包全部倒入)
将 struts-2.3.16.1\apps下的struts2-blank.war解压
倒入\struts2-blank\WEB-INF\lib下的所有包到web项目的lib文件夹下
2 .写一个action类,可实现接口Action,也可继承类ActionSupport,也可都没有
public class helloAction {
public String execute(){
return "ok";
}
}
3.struts配置文件
<?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>
<package name="hellodemo" extends="struts-default" namespace="/">
<action name="hello" class="MyAction.helloAction">
<result name="ok">/hello.jsp</result>
</package>
</struts>
对于dtd约束的引入也在之前那个解压文件路径\struts2-blank\WEB-INF\src\java下面,struts.xml
4.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">
<display-name>Struts Blank</display-name>
<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>
</web-app>