修改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>