struts2 struts.xml中的methods方法

修改struts.xml 文件 实现 函数传递调用

stryts.xml

<?xml version="1.0" encoding="GBK" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

	<include file="login.xml" />
    <package name="HelloPackage" namespace="/hello" extends="struts-default">
    	<action name="Hello" class="com.zxl.action.Action" method="addOtherMethod" >
    		<result name="success">/success.jsp</result>
    		<result name="failure">/error.jsp</result>
    	</action>
    </package>
    
    <package name="search" namespace="/" extends="struts-default">
    	<action name="search*">
    		<result>/search{1}.jsp</result>
    	</action>
    </package>
    
</struts>
Action.java

package com.zxl.action;

import com.zxl.service.FinderService;

public class Action {

	private String bestTutorialSite;
	private String language;
	
	public String  execute(){
		FinderService tutorialFinderService = new FinderService();
		System.out.println(getLanguage());
		setBestTutorialSite(tutorialFinderService.getBestTutorialSite(getLanguage()));
		
		System.out.println("EXECUTE method called");
		return "success";
	}
	
	public String addOtherMethod(){
		System.out.println(" add some Other Method EXECUTE");
		return "success";
	}
	public String getOtherMethod(){
		System.out.println(" get some Other Method EXECUTE");
		return "success";
	}
	
	public String getBestTutorialSite() {
		return bestTutorialSite;
	}

	public void setBestTutorialSite(String bestTutorialSite) {
		this.bestTutorialSite = bestTutorialSite;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}
	
}



<?xml version="1.0" encoding="GBK" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

	<include file="login.xml" />
    <package name="HelloPackage" namespace="/hello" extends="struts-default">
    	<action name="*" class="com.zxl.action.Action" method="{1}" >
    		<result name="success">/success.jsp</result>
    		<result name="failure">/error.jsp</result>
    	</action>
    </package>
    
    <package name="search" namespace="/" extends="struts-default">
    	<action name="search*">
    		<result>/search{1}.jsp</result>
    	</action>
    </package>
    
</struts>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值