zoukankan      html  css  js  c++  java
  • struts2入门---环境搭建

    1.struts2环境搭建

    下载: http://struts.apache.org/

    我们这里直接选择这个版本的struts

    安装:将struts2核心jar包导入web工程lib目录下

    这里需要注意一个问题:

    xwork-core-2.3.16.jar 2.5版本以前的版本都有这个,但在2.5版本就没有了.其实他们只是将它合并到struts2-core-2.5.12.jar里面了.

     接下来就是关键的了 struts2的配置

    因为struts2是通过Filter来控制的.所以需要配置Filter.

    <?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>struts2</display-name>
      
      <!-- 配置Struts2的Filter -->
      <filter>
          <filter-name>struts2</filter-name>
          <filter-class>org.apache.struts2.dispatcher.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>
    web.xml

     现在就是使用struts了 配置struts.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
            "http://struts.apache.org/dtds/struts-2.5.dtd">
    
    
    <struts>
       <package name="default" extends="struts-default">
               <action name="default" class="com.struts.hello.helloWorld" method="execute">
                   <result name="success">/hello.jsp</result>
               </action>
       </package>
    </struts>
    struts.xml

    index.jsp

    <a href="default.action">hello world</a>

    现在只需要创建一个hello.jsp就可以进行测试了...

    这样就用struts实现了控制页面的跳转逻辑...

    ---恢复内容结束---

    1.struts2环境搭建

    下载: http://struts.apache.org/

    我们这里直接选择这个版本的struts

    安装:将struts2核心jar包导入web工程lib目录下

    这里需要注意一个问题:

    xwork-core-2.3.16.jar 2.5版本以前的版本都有这个,但在2.5版本就没有了.其实他们只是将它合并到struts2-core-2.5.12.jar里面了.

     接下来就是关键的了 struts2的配置

    因为struts2是通过Filter来控制的.所以需要配置Filter.

    <?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>struts2</display-name>
      
      <!-- 配置Struts2的Filter -->
      <filter>
          <filter-name>struts2</filter-name>
          <filter-class>org.apache.struts2.dispatcher.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>
    web.xml

     现在就是使用struts了 配置struts.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
            "http://struts.apache.org/dtds/struts-2.5.dtd">
    
    
    <struts>
       <package name="default" extends="struts-default">
               <action name="default" class="com.struts.hello.helloWorld" method="execute">
                   <result name="success">/hello.jsp</result>
               </action>
       </package>
    </struts>
    struts.xml

    index.jsp

    <a href="default.action">hello world</a>

    现在只需要创建一个hello.jsp就可以进行测试了...

    这样就用struts实现了控制页面的跳转逻辑...

    文章未经版主同意不可任意转载,如有需要请标明文章出处。
  • 相关阅读:
    window上部署Flask
    PIP超时
    覆盖内敛样式
    解决js导出csv中文乱码
    没有为请求的 URL 配置默认文档,并且没有在服务器上启用目录浏览。
    nuget加载本地包
    DataTable表头对不齐、添加参数等方法总结
    根据class判断
    element-ui的table动态生成表头和数据,且表中数据可编辑
    VScode快捷键、Chrome快捷键知识小总结和状态码
  • 原文地址:https://www.cnblogs.com/qihangzj/p/7207496.html
Copyright © 2011-2022 走看看