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

  • 相关阅读:
    设计模式之桥接模式
    设计模式之代理模式
    设计模式之原型模式
    设计模式之建造者模式
    设计模式之抽象工厂模式
    设计模式之工厂模式
    设计模式之单例模式
    FR算法(Fruchterman-Reingold)
    zoj 3822 Domination (概率dp 天数期望)
    hdu 5023 A Corrupt Mayor's Performance Art(线段树)
  • 原文地址:https://www.cnblogs.com/tenWood/p/7087677.html
Copyright © 2011-2022 走看看