转载请注明出处 csdn wankaiming
1.导入struts2的相关包
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
freemarker-2.3.15.jar
ognl-2.7.3.jar
commons-logging-1.0.4.jar
commons-fileupload-1.2.1.jar
2.配置struts2.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!--解决中文乱码 -->
<constant name="struts.i18n.encoding" value="GB18030"></constant>
<!--此处包名可以自己取-->
<package name="default" extends="struts-default" namespace="/">
<interceptors>
<interceptor name="instance" class="com.onlineexamfront.Interceptor.InstanceInterceptor"></interceptor>
<!-- 定义拦截器栈 自定义拦截器的引用 里面可以获取dao接口 -->
<interceptor-stack name="yourstack">
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="instance"></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="examstack"></default-interceptor-ref>
</package>
<!--此处导入其他的配置文件,按功能分配置文件可以结构更加清晰-->
<include file="com/onlineexamfront/student/student.xml"></include>
<include file="com/onlineexamfront/question/question.xml"></include>
</struts> 3.配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!--配置struts2控制器 -->
<filter>
<filter-name>cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>上面的配置内容基本很全了 希望对你有帮助

本文详细介绍Struts2框架的基本配置流程,包括所需核心库文件、struts2.xml及web.xml配置示例,帮助读者快速搭建开发环境。
1152

被折叠的 条评论
为什么被折叠?



