---
title: "jsp页面取struts2 action的变量供java、servlet使用"
author: "jiang_xiaohan"
date: "2012-12-10T16:48:26Z"
tags: []
categories: ["Web前端"]
slug: "jsp-struts2-action-java-servlet"
draft: false
lastmod: "2012-12-10T16:48:26Z"
id: 1745109
url: "https://jiang-xiaohan.iteye.com/blog/1745109"
---

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
%>