struts2框架 基础搭建

一、 当然是导入所需Jar包到lib下:
 asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.3.2.jar
commons-io-2.2.jar
commons-lang3-3.2.jar
freemarker-2.3.22.jar
javassist-3.11.0.GA.jar
log4j-api-2.3.jar
log4j-core-2.3.jar
ognl-3.0.19.jar
struts2-core-2.3.30.jar
xwork-core-2.3.30.jar

二、编写web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>01_struts2_hello</display-name>
  <filter>
  	<filter-name>struts2</filter-name>
  	<!-- 配置struts2核心控控制器,
  		复制struts2-core-2.3.30.jar的包下面的
  			org.apache.struts2.dispatcher.ng.filter下面的
  				StrutsPrepareAndExecuteFilter 包名跟类名,再去掉后面的.class -->
  	<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>
  
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

三、在src下新建一个struts2.xml文件:


上代码:

<?xml version="1.0" encoding="UTF-8"?>
<!-- 找到struts2-core-2.3.30.jar展开找到struts-default.xml打开,复制35-39行头文件过来,用“</struts>”结下尾-->
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

</struts>




猜你喜欢

转载自blog.csdn.net/u014304688/article/details/54170652
今日推荐