• struts2基础


    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

  • 相关阅读:
    GNU软件FTP下载汇总
    设置git的代理服务器
    今天发现一个Convert.ToDateTime的异常,算不算微软的bug呢?
    无线电空间传输损耗衰减计算(转帖)
    使用ArcGis10.2通过Dem提取山顶点(原创)
    VC++编译zlib
    VC++编译libpng
    vc++编译libtiff4.0.4
    VC++编译GSL
    libCEF总结02字符串
  • 原文地址:https://www.cnblogs.com/x-jingxin/p/8447190.html
Copyright © 2020-2023  润新知