在struts2 的action里,想用request ,怎么办?
在struts2里,我想把一些值存如request ,以便在页面上获取,,但struts2里面的 action里没有 request 这样的参数,我用HttpServletRequest request = ServletActionContext.getRequest(); 却报
空指针,我该怎么获取request呢?
struts.xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN "
"http://struts.apache.org/dtds/struts-2.0.dtd ">
<struts>
<constant name= "struts.devMode " value= "false " />
<constant name= "struts.i18n.encoding " value= "UTF-8 " />
<constant name= "struts.action.extension " value= "html " />
<constant name= "struts.objectFactory " value= "spring " />
<constant name= "struts.custom.i18n.resources "
value= "ApplicationResources,errors " />
<constant name= "struts.multipart.maxSize " value= "2097152 " />
<constant name= "struts.ui.theme " value= "css_xhtml " />
<constant name= "struts.codebehind.pathPrefix "
value= "/WEB-INF/pages/ " />
<!-- Include Struts defaults -->
<include file= "struts-default.xml " />
<!-- Configuration for the default package. -->
<package name= "default " extends= "struts-default ">
<default-interceptor-ref name= "defaultStack " />
<!-- DashBoard-->
<action name= "dashBoard " method= "showDashBoard "
class= "com.flips.action.DashBoard ">
<result name= "success "> dashBoard.jsp </result>
<interceptor-ref name= "basicStack "/>
</action>
</package>
</struts>
------解决方案--------------------在ACTION里面引入
HttpServletRequest request = ServletActionContext.getRequest();