天天看点

struts2环境的搭建

(第一步)新建web应用,web-inf下lib引入jar包如下:

struts2环境的搭建
struts2环境的搭建
struts2环境的搭建

(第二步)配置web.xml

<?xmlversion="1.0" encoding="UTF-8"?>

<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"version="3.0">

 <display-name>test</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>

 <welcome-file-list>

   <welcome-file>index.jsp</welcome-file>

 </welcome-file-list>

</web-app>

截图:

struts2环境的搭建
struts2环境的搭建
struts2环境的搭建

(第三步)配置struts.xml

主要是action的配置及跳转路径

struts2环境的搭建
struts2环境的搭建
struts2环境的搭建

(第四步)完成action类的写法

struts2环境的搭建
struts2环境的搭建
struts2环境的搭建

注意:struts.xml一定在web目录中,eclipse自动生成的工程可能会生成build文件夹,鼻翼路径也在下面的classes下,这时将编译路径手动配置在WebContent下 web-inf内classes目录下就可以了,否则会出现找不到action的错误

继续阅读