• Struts配置应用1


    一.导包

    <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.5.13</version>
    </dependency>
    二.配置struts.xml文件
     1 <?xml version="1.0" encoding="UTF-8"?>
     2 
     3 <!DOCTYPE struts PUBLIC
     4         "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
     5         "http://struts.apache.org/dtds/struts-2.5.dtd">
     6 <struts>
     7     <package name="default" extends="struts-default" namespace="/">
     8         <action name="demo" class="com.yztc.demo.action.DemoAction">
     9             <result name="index" >index.jsp</result>
    10         </action>
    11     </package>
    12 </struts>

    三.配置web.xml文件

     1 <!DOCTYPE web-app PUBLIC
     2  "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     3  "http://java.sun.com/dtd/web-app_2_3.dtd" >
     4 
     5 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
     6            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     7            xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
     8                       http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     9            version="3.1">
    10   <filter>
    11     <filter-name>struts2</filter-name>
    12     <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    13   </filter>
    14   <filter-mapping>
    15     <filter-name>struts2</filter-name>
    16     <url-pattern>/*</url-pattern>
    17   </filter-mapping>
    18 </web-app>

    四.创建一个class继承ActionSupport,如下:

     1 package com.yztc.demo.action;
     2 
     3 import com.opensymphony.xwork2.ActionSupport;
     4 
     5 /**
     6  * _ooOoo_
     7  * o8888888o
     8  * 88" . "88
     9  * (| -_- |)
    10  * O = /O
    11  * ___/`---'\____
    12  * .   ' \| |// `.
    13  * / \||| : |||// 
    14  * / _||||| -:- |||||- 
    15  * | | \ - /// | |
    16  * | \_| ''---/'' | |
    17  *  .-\__ `-` ___/-. /
    18  * ___`. .' /--.-- `. . __
    19  * ."" '< `.___\_<|>_/___.' >'"".
    20  * | | : `- \`.;` _ /`;.`/ - ` : | |
    21  *   `-. \_ __ /__ _/ .-` / /
    22  * ======`-.____`-.___\_____/___.-`____.-'======
    23  * `=---='
    24  * .............................................
    25  *
    26  * @author bindu
    27  * @date 2017-10-23 20:31
    28  */
    29 
    30 
    31 public class DemoAction extends ActionSupport {
    32     @Override
    33     public String execute() throws Exception {
    34         System.out.println("你死不死啊!!!");
    35         return "index";
    36     }
    37 }
  • 相关阅读:
    centos ssh远程登陆
    Vim 技巧
    php and js to facebook登陆 最佳实践
    vim 编辑器常规操作
    js 函数定义三种方式
    ORDER BY 默认升序排列
    sql = 和<>遵循的sql-92标准的设置SET ANSI_NULLS ON
    添加FB登陆时,需要curl扩展
    array(1) { [0]=> int(5) }和array(1) { [0]=> string(1) "5" }
    Android第三方推送引擎比较
  • 原文地址:https://www.cnblogs.com/1218-mzc/p/7725365.html
Copyright © 2020-2023  润新知