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实现了控制页面的跳转逻辑...

    文章未经版主同意不可任意转载,如有需要请标明文章出处。
  • 相关阅读:
    软件设计7个原则
    vue.js 样式绑定 font-size 问题
    实例理解scala 隐式转换(隐式值,隐式方法,隐式类)
    著名端口整理(常用服务的默认端总结)
    .NET Core Web API 实现大文件分片上传
    ngnix反向代理tomcat,ssl证书配置及自定义错误页面
    微信登录闪退
    gradle如何配置阿里云的中央仓库
    HashMap底层实现和原理
    关于Java中String类的hashCode方法
  • 原文地址:https://www.cnblogs.com/qihangzj/p/7207496.html
Copyright © 2011-2022 走看看