zoukankan      html  css  js  c++  java
  • struts2的搭建和理解

    1.将struts文件中需要的jar包放入web项目中

     2.拷贝struts.xml文件

    3.配置tomcat

    4.配置struts.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>
        <!--  
        <constant name="struts.enable.DynamicMethodInvocation" value="false" />
        <constant name="struts.devMode" value="true" />
    
        <package name="default" namespace="/" extends="struts-default">
    
            <default-action-ref name="index" />
    
            <global-results>
                <result name="error">/error.jsp</result>
            </global-results>
    
            <global-exception-mappings>
                <exception-mapping exception="java.lang.Exception" result="error"/>
            </global-exception-mappings>
    
            <action name="index">
                <result type="redirectAction">
                    <param name="actionName">HelloWorld</param>
                    <param name="namespace">/example</param>
                </result>
            </action>
        </package>
        -->
        <include file="example.xml"/>
        
        
        <package name="default" namespace="/" extends="struts-default">
    
           
    
            <global-results>
                <result name="error">/error.jsp</result>
            </global-results>
    
            <global-exception-mappings>
                <exception-mapping exception="java.lang.Exception" result="error"/>
            </global-exception-mappings>
    
            <action name="hello">
                <result >
                    /index.jsp
                </result>
            </action>
        </package>
    
        <!-- Add packages here -->
       
    </struts>

    5.配置web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
        <display-name>Struts Blank</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>

     6.写jsp

    7.Run as server

    8.结果

    struts做的事情就是逻辑的跳转,也就是控制器

  • 相关阅读:
    【小程序】请求与封装
    【小程序】生命周期
    【小程序】项目结构
    【笔记】vue-cli 开发环境中跨域连接后台api(vue-resource 跨域post 请求)
    【笔记】npm 安装 vue-cli
    【笔记】css 实现宽度自适应屏幕 高度自适应宽度
    【笔记】css 1像素边框
    【笔记】让360浏览器用chrome 内核渲染你的网页
    【实践】require.js + r.js 代码打包压缩初体验
    【笔记】学校项目开发中所了解的一些浏览器之间的差异
  • 原文地址:https://www.cnblogs.com/S-Mustard/p/7563026.html
Copyright © 2011-2022 走看看