• struts2学习(1)struts2 helloWorld


    一、struts2简介:

    二、helloWorld:

    1)工程结构:

    HelloWorldAction.java:

    package com.cy.action;
    
    import com.opensymphony.xwork2.Action;
    
    public class HelloWorldAction implements Action{
    
        public String execute() throws Exception {
            System.out.println("执行了Action的默认方法");
            return SUCCESS;
        }
    
    }

    struts.xml配置文件:

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">
    
    <struts>
    
        <!-- 可以创建很多的package,用name来区分 -->
        <package name="helloWorld" extends="struts-default">
            <action name="hello" class="com.cy.action.HelloWorldAction">
                <!-- 默认是转发,转发到helloWorld.jsp -->
                <result name="success">helloWorld.jsp</result>
            </action>
        </package>
    
    </struts>

    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_2_5.xsd" 
             id="WebApp_ID" version="2.5">
      <display-name>Struts2Chap01</display-name>
      <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>
      
          <filter>
            <filter-name>Struts2</filter-name>
            <!-- struts2的核心控制器 -->
            <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>
        
            
    </web-app>

    helloWorld.jsp:

    <body>
        struts2你好!!
    </body>

    2)测试结果:

    浏览器中访问:http://localhost:8080/Struts2Chap01/hello

  • 相关阅读:
    Dispatcher及线程操作
    MVVM中轻松实现Command绑定(三)任意事件的Command
    MVVM Light中的Message
    Prism
    Prism的IEventAggregator事件聚合器, 事件订阅发布, ViewModel之间的通讯
    文件写操作--WriteLog
    【Golang】Debug :decoding dwarf section info at offset 0x0: too short
    【Golang 接口自动化03】 解析接口返回XML
    【Golang 接口自动化02】使用标准库net/http发送Post请求
    【Golang 接口自动化01】使用标准库net/http发送Get请求
  • 原文地址:https://www.cnblogs.com/tenWood/p/7087677.html
Copyright © 2020-2023  润新知