jsp页面通过 request对象直接获取 struts2 Action的变量的值。

来源:互联网 发布:java web权限管理 编辑:程序博客网 时间:2024/05/04 01:29
假设在Action类里有这么一个变量

private String str = "Hello jsp and struts2";

还必须有str的get方法。

在JSP页面我们要引入org.apache.struts2.ServletActionContext
<%@page import="org.apache.struts2.ServletActionContext"%>

然后
<%
String str = request.getAttribute("str");
System.out.println(str); //结果将输出: Hello jsp and struts2
%>
0 0
原创粉丝点击