jsp页面通过 request对象直接获取 struts2 Action的变量的值。
假设在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
%>
假设在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
%>
本文介绍如何在Struts2框架中使用JSP页面通过request对象直接获取Action类中的变量值。具体实现需要确保Action类中有对应的get方法,并在JSP页面引入必要的包。
2495

被折叠的 条评论
为什么被折叠?



