Struts HelloWorld
第一步 导jar包
commons-fileupload-1.2.2.jar 【文件上传相关包】
commons-io-2.0.1.jar 【输入输出相关包】
struts2-core-2.3.4.1.jar 【struts2核心功能包】
xwork-core-2.3.4.1.jar 【Xwork核心包】
ognl-3.0.5.jar 【Ognl表达式功能支持表】
commons-lang3-3.1.jar 【struts对java.lang包的扩展】
freemarker-2.3.19.jar 【struts的标签模板库jar文件】
javassist-3.11.0.GA.jar 【struts对字节码的处理相关jar】
第二步 配置web.xml
<!-- 引入struts核心过滤器 -->
<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>
第三步 开发action 处理请求
package com.struts.action;
import com.opensymphony.xwork2.ActionSupport;
public class helloaction extends ActionSupport {
// 处理请求
public String execute() throws Exception {
System.out.println("访问到了action,正在处理请求");
System.out.println("调用service");
return "success";
}
}
第四步 配置 struts.xml 文件放在 src下
<?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>
<package name="xxxx" extends="struts-default">
<action name="hello" class="com.struts.action.helloaction" method="execute">
<result name="success">/MyJsp.jsp</result>
</action>
</package>
</struts>
好 struts helloworld 就完工了。