zoukankan      html  css  js  c++  java
  • 第一个Struts2程序之HelloWorld

    1、Struts2 简介

    Struts 2Struts的下一代产品,是在 struts 1WebWork的技术基础上进行了合并的全新的Struts 2框架。其全新的Struts 2的体系结构与Struts 1的体系结构差别巨大。Struts 2WebWork为核心,采用拦截器的机制来处理用户的请求,这样的设计也使得业务逻辑控制器能够与ServletAPI完全脱离开,所以Struts 2可以理解为WebWork的更新产品。虽然从Struts 1Struts 2有着太大的变化,但是相对于WebWorkStruts 2的变化很小。

    2、Struts2实例之HelloWorld

    2.1 web.xml配置代码

    1 <filter>
    2     <filter-name>struts2</filter-name>
    3     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    4 </filter>
    5 <filter-mapping>
    6     <filter-name>struts2</filter-name>
    7     <url-pattern>/*</url-pattern>
    8 </filter-mapping>

    2.2 struts.xml配置代码

    1 <struts>
    2     <package name="helloWorld" extends="struts-default">
    3         <action name="hello" class="com.action.HelloWorldAction">
    4             <result name="success">helloWorld.jsp</result>
    5         </action>
    6     </package>
    7 </struts>

    2.3 HelloWorldAction代码

    1 public class HelloWorldAction implements Action{
    2 
    3     @Override
    4     public String execute() throws Exception {
    5         System.out.println("执行了Action默认方法!!");
    6         return SUCCESS;
    7     }
    8 }

    2.4 helloWorld.jsp代码

    1 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    2 <html>
    3 <head>
    4     <title>Struts2</title>
    5 </head>
    6 <body>
    7 Struts2大爷你好!
    8 </body>
    9 </html>

      每天进步一点点,勿忘初心,一切都是最好的安排。

  • 相关阅读:
    撩课-Web大前端每天5道面试题-Day15
    撩课-Web大前端每天5道面试题-Day14
    撩课-Java每天5道面试题第26天
    撩课-Java每天5道面试题第25天
    撩课-Web大前端每天5道面试题-Day13
    撩课-Java每天5道面试题第24天
    撩课-每天刷Web面试题(前10天汇总)-Day12
    撩课-Java每天5道面试题第23天
    撩课-Web大前端每天5道面试题-Day11
    java设计模式-策略模式
  • 原文地址:https://www.cnblogs.com/wangchaoyuan/p/6213188.html
Copyright © 2011-2022 走看看