struts2在配置文件与JSP中用OGNL获取Action属性

参考:Struts与OGNL结合

struts2在配置文件中可以调用Action的属性,在JSP页面也可以取出Action的属性值(前提是属性有get,set方法)。

第一个例子:

1.Action中

//文件下载名
public String getDownloadFileName(){
String downloadFileName = "";
String filename = fileName + ".xls";
try {
downloadFileName = URLEncoder.encode(filename,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return downloadFileName;
}

2.配置文件中filename="${downloadFileName}"调用Action中的属性

<!-- 文件Excel模板下载 -->
<action name="exportWebExcel" class="Action.Excel.ExportWebExcel">
<result type="stream">
<!-- 其他的参数在类中设置或者使用默认 -->
<param name="contentType">application/octet-stream</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">attachment;filename="${downloadFileName}"</param>
<param name="bufferSize">8192</param>
</result>
</action>

第二个例子:

Action

package Demo1;

import javax.print.attribute.standard.RequestingUserName;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; import utils.CheckCookie; /**
* Demo1主页,访问主页要先验证cookie
*
* @author: qlq
* @date : 2017年8月29日下午12:02:31
*/
public class Demo1Action extends ActionSupport { private String gotoUrl; public String getGotoUrl() {
return gotoUrl;
} public void setGotoUrl(String gotoUrl) {
this.gotoUrl = gotoUrl;
} @Override
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
if (CheckCookie.checkCookie(request))
return SUCCESS;
// 登陆失败后将gotoUrl写到JSP页面
gotoUrl = "/demo1/main.action";
return LOGIN;
} }

配置文件中:

    <package name="sso" namespace="/sso" extends="struts-default">
<action name="login" class="SSOAction.LoginAction">
<result name="success" type="redirect">${gotoUrl}</result>
</action>
</package>

例子3:   JSP页面中取出Action属性

属性有get,set方法即可,在JSP页面中也可以用OGNL表达式取出属性值,struts会将当前Action对象的属性放入值栈。

package Demo2;

import javax.print.attribute.standard.RequestingUserName;
import javax.servlet.http.HttpServletRequest; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; import utils.CheckCookie; /**
* Demo2主页,访问主页要先验证cookie
*
* @author: qlq
* @date : 2017年8月29日下午12:02:31
*/
public class Demo2Action extends ActionSupport { private String gotoUrl; public String getGotoUrl() {
return gotoUrl;
} public void setGotoUrl(String gotoUrl) {
this.gotoUrl = gotoUrl;
} @Override
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
if (CheckCookie.checkCookie(request))
return SUCCESS;
// 登陆失败后将gotoUrl写到JSP页面
gotoUrl = "/demo2/main.action";
return LOGIN;
} }

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoYAAADfCAIAAADk9oU4AAAgAElEQVR4nO2du47sNraG9Tw7dqSkX2KnB04a9Q4VGBIG6LwAj1Bw0Gl7AE1lAwWeoI8KHUwy48hKKtjuzLCyeYDDE+i2SC5SN0olqv4PRKNLFCmKVPGvRVJcgQAAAADABgj++O//KeF/zegnIyAgICAgIDgJvCSzp0KSERAQEBAQlguQZAQEBAQEhE0ESDICAgICAsImwmhJ/sfP0dPPv828qpNMEBAQEBAQ9hQgyQgICAgICJsIAyT59/y7+O9vd5Hk3/Pv4vNffr9/NSEgICAgICwd+iT5P38P4vi7f/75x52s5Le/xUEc/89/7l9TCAgICAgIiwabJP/rn2cqh1SSf/0leYqipyh6itJ/kLTkePT0Y/4rzfnfaRcVNZL8Lf8+in74t3Ja8tO37khVjOpnAQICAgICwl6DUZLf/hYH8qBxJ8mtoP73z59+7Ozdf/xMFfrPn37sVPnXXxIq3tRK/sfPknjzBvTv+XdxHPytuHt9ISAgICAgLBR4Sf7LX+Mg/vubdvwPXTL/ndZaq9u73/Lva3v3tx/kKCkTahZ3SfRQ/E8cB3/N/3XvKkNAQEBAQFgiTLKSVUlOfvrGqmmjxJpay5n8+dOP0fe//PlHZUyzc8ywkhEQEBAQ9h4mziV358+3kqtMfsx//e9vP7AmMllihoCAgICAsNcwc8X1bz9EtYH7BzuXzEwY//nTj3Q2ujv5h59T3UTGimsEBAQE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AAAIBhbGLFdXYx2Jdl/qzMBDfwE7pCiF5JLvNnTn0tGdolGSuuAQAAOGEL7yWzC7vak/NnwwJpdQU1Xd5lkWQ54ZAMbZKM95IBAAA44v67d92uZyyJAgAAAO4uydjUGgAAABBiA5IMAAAAACEgyQAAAMBGgCQDAAAAmwCSDAAAAGwCSDIAAACwCSDJAAAAwCaYKcnSK0zmLalH4CQTAAAAwDvmSbLsvgmSDAAAAExmgCSr+192ZBdpl49VJRk7WQIAANgXfZJs8XGkieLKVjL8PQAAANgTNkk2+lJsY2X3TZWaEucNkqsGyamD4nKxSBl/D7rLpiJ9ipI38iOgKiH24wQAALADjJKcXeLANjLMuG/6SKkDpfItkb0zdQpdviWdKiteEamVrPhL5g3o8hrGBt+OAAAAgD+wklyeznFgmD+ukRd2VaiS2fo01O3dMn+u7d3iRY6SMqFmcZeEKc0hjuFOCgAAgNdMs5J5902cJCdvJaumjRJrai1nUr4ltUvjzzzh55hhJQMAANgFk+aSDaud3VvJVSZJ/imKF9ZEtqw+AwAAALzi/wGYRnRlg4iTKgAAAABJRU5ErkJggg==" alt="" />

 -------------struts只写get方法,不写属性名字用${属性名}也会调用get方法-------------------

 struts只写一个get方法,不写属性名,也可以获取到get方法返回的值,由此可见${name}是调用getName()方法。

 例一:

类中只有getTest方法:

package cn.xm.exam.action.exam.exam;
/**
* 增加考试Action
*
* @author QiaoLiQiang
* @time 2017年10月14日下午4:55:27
*/
@Controller
@Scope("prototype")
@SuppressWarnings("all")
public class Test2Action extends ActionSupport { public String getTest() {
return "这个是只有get方法";
} @Override
public String execute() throws Exception {
return super.execute();
}
}

配置文件:

        <action name="test" class="test2Action">
<result name="success" type="json">
<param name="root">test</param>
</result>
</action>

测试:

struts2在配置文件与JSP中用OGNL获取Action属性

例子二:

将上面类进行改造:

package cn.xm.exam.action.exam.exam;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import com.opensymphony.xwork2.ActionSupport; /**
* 增加考试Action
*
* @author QiaoLiQiang
* @time 2017年10月14日下午4:55:27
*/
@Controller
@Scope("prototype")
@SuppressWarnings("all")
public class Test2Action extends ActionSupport {
private String test = "sssssss"; public String getTest() {
return "这个是只有get方法";
} @Override
public String execute() throws Exception {
return super.execute();
} public void setTest(String test) {
this.test = test;
} }

结果:

struts2在配置文件与JSP中用OGNL获取Action属性

 总结:

  当我们在struts配置文件或者JSP页面中调用${name}的时候实际是调用getName()方法,因此有时候只需要写getName方法而不用写私有属性与set方法也可以完成获取。

上一篇:PHP 配置文件中open_basedir选项作用


下一篇:maven配置文件中modules的作用