码迷,mamicode.com
首页 > 其他好文 > 详细

struts2基础

时间:2018-02-13 19:28:01      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:post   display   分享   load   tomcat   3.0   coding   xtend   namespace   

1、下载struts2源码包:http://struts.apache.org/download.cgi

必需包:

技术分享图片

技术分享图片

2、新建web项目

技术分享图片

 

 3、配置struts2.xml:

<?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="hello" namespace="/" extends="struts-default">
         <action name="HelloWorld" class="com.struts2.action.HelloWorld">
            <result>helloWorld.jsp</result>
        </action>
     </package>
</struts>

需要注意这里的是xml中的struts的版本号应该与项目struts2.jar包一致

4、配置web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>struts2</display-name>
  
  <!-- 
  StrutsPrepareAndExecuteFilter类是Struts2的控制器,用于过滤
     客户端的所有请求。它是Struts2框架的入口,如果未在web.xml
     中进行配置,Struts2框架就会失去其作用
  
   -->
  <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>*.action</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>

5、在tomcat中启动项目

6、访问:http://localhost:8080/struts2/HelloWorld.action

 

struts2基础

标签:post   display   分享   load   tomcat   3.0   coding   xtend   namespace   

原文地址:https://www.cnblogs.com/x-jingxin/p/8447190.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!