zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Android 5.X新特性之RecyclerView基本解析及无限复用
    Android 网络框架之Retrofit2使用详解及从源码中解析原理
    Android 源码解析之AsyncTask
    Business Logic
    WHO AM I
    黑洞
    俄罗斯方块
    还记得八皇后的解法吗
    汝之蜜糖,吾之砒霜
    项目为什么会失败
  • 原文地址:https://www.cnblogs.com/tenWood/p/7087677.html
Copyright © 2011-2022 走看看