• Struts配置应用2


    一.导包

    <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.5.13</version>
    </dependency>
    <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-convention-plugin</artifactId>
    <version>2.5.13</version>
    </dependency>
    <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-json-plugin</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 
     7 <struts>
     8     <constant name="struts.devMode" value="true"/>
     9     <constant name="struts.serve.static.browserCache" value="false"/>
    10     <!--支持动态调用-->
    11     <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
    12     <!--在浏览器上访问的路径 == namespace +   name    -->
    13     <package name="default" extends="struts-default,json-default" namespace="/">
    14         <action name="register" class="com.yztc.demo.action.AccountAction" method="register">
    15             <result name="success">/test.jsp</result>
    16             <allowed-methods>register</allowed-methods>
    17         </action>
    18         <action name="login" class="com.yztc.demo.action.AccountAction" method="login">
    19             <result name="success">/test.jsp</result>
    20             <allowed-methods>login</allowed-methods>
    21         </action>
    22         <action name="update" class="com.yztc.demo.action.AccountAction" method="update">
    23             <result name="success">/test.jsp</result>
    24             <allowed-methods>update</allowed-methods>
    25         </action>
    26     </package>
    27 </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   <display-name>Archetype Created Web Application</display-name>
    11   <filter>
    12     <filter-name>StrutsPrepareAndExecuteFilter</filter-name>
    13     <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    14   </filter>
    15   <filter-mapping>
    16     <filter-name>StrutsPrepareAndExecuteFilter</filter-name>
    17     <url-pattern>/*</url-pattern>
    18   </filter-mapping>
    19 </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-24 14:59
    28  */
    29 
    30 
    31 public class AccountAction extends ActionSupport {
    32     public String  register(){
    33         return SUCCESS;
    34 
    35     }
    36     public String login(){
    37         return SUCCESS;
    38 
    39     }
    40     public String update(){
    41         return SUCCESS;
    42 
    43     }
    44 }

     五.配置test.jsp 文件:

     1 <%--
     2   Created by IntelliJ IDEA.
     3   User: bindu
     4   Date: 2017/10/24
     5   Time: 15:21
     6   To change this template use File | Settings | File Templates.
     7 --%>
     8 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
     9 <html>
    10 <head>
    11     <title>Title</title>
    12 </head>
    13 <body>
    14         测试代码
    15 </body>
    16 </html>
  • 相关阅读:
    2019.6.1 模拟赛——[ 费用流 ][ 数位DP ][ 计算几何 ]
    LOJ 2721 「NOI2018」屠龙勇士——扩展中国剩余定理
    AGC033 D~F——[ 值放到角标的DP ][ 思路+DP ][ 思路 ]
    LOJ 2719 「NOI2018」冒泡排序——模型转化
    LOJ 3094 「BJOI2019」删数——角标偏移的线段树
    CF 717A Festival Organization——斯特林数+递推求通项+扩域
    LOJ 3090 「BJOI2019」勘破神机——斯特林数+递推式求通项+扩域
    洛谷 4723 【模板】线性递推——常系数线性齐次递推
    bzoj 3924 幻想乡战略游戏 —— 动态点分治
    计算几何整理
  • 原文地址:https://www.cnblogs.com/1218-mzc/p/7725398.html
Copyright © 2020-2023  润新知