• Struts2之动态方法调用


    1.感叹号

    前台页面

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <a href="user!login.action">登录</a><br>
    <a href="user!register.action">注册</a>
    </body>
    </html>
    

    struts.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
    <struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
    <package name="jiangwenwen" namespace="/" extends="struts-default">
    
    	<action name="user" class="cn.jiangwenwen.action.UserAction">
    		<result name="test">/test.jsp</result>
    		<allowed-methods>login,register</allowed-methods>
    	</action>
    </package>
    </struts> 
    

    Action方法

    package cn.jiangwenwen.action;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class UserAction extends ActionSupport{
    	
    	public String login() {
    		
    		System.out.println("这是登陆!");
    		
    		return "test";
    		
    	}
    	
    	public String register() {
    		
    		System.out.println("这是注册!");
    		
    		return "test";
    			
    	}
    	
    
    }
    
    

    2.通配符

    jsp页面

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <a href="user_login.action">登录</a><br>
    <a href="user_register.action">注册</a>
    </body>
    </html>
    

    struts.xml配置

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">
    <struts>
    <constant name="struts.enable.DynamicMethodInvocation" value="true"></constant>
    <package name="jiangwenwen" namespace="/" extends="struts-default">
    	   <!--使用通配符优化上面的步骤操作,{1}代表*第1次出现的位置-->
    	 <action name="user_*" class="cn.jiangwenwen.action.UserAction" method="{1}">
                <result name="test">/test.jsp</result>
                <allowed-methods>login,register</allowed-methods>
            </action>
    </package>
    </struts> 
    
  • 相关阅读:
    C语言、指针的指针和野指针的问题
    常见证书格式和转换
    cation,validation,qualification有何区别
    Cygwin + OpenSSH FOR Windows的安装配置
    python static variable
    45个与众不同的非常棒网页设计案例
    65个精心设计的富有灵感的电子商务网站案例
    60个抢眼的企业网站设计案例
    26个有用的创建视觉图片网站的jQuery插件
    Android 图像用户界面免费的PSD设计文件
  • 原文地址:https://www.cnblogs.com/jiangwenwen1/p/9460175.html
Copyright © 2020-2023  润新知