一,Struts2标签不支持EL表达式,应该用Ognl表达式,比如在<s:if>标签中
<s:if test="#msg==null">
<span id="welcomeInfo" >欢迎使用XX后台管理系统! </span> </s:if>
<s:else>
<span id="wrongInfo">${msg}</span>
</s:else>
其中判断是用#msg==null来判断action中传递的参数msg是否为空
二,Action中如何将参数传递到jsp页面呢
ActionContext ac=ActionContext.getContext();
ac.put("msg", msg);
上面就相当于
HttpServletRequest传值,其余还有
ac.getApplication.put("","");
ac.getSession.put("","");
三,关于Struts2.xml文件中的Action的result中配置传递值
<result name="success" type="redirect">
<param name="location">/Login.jsp</param>
</result>
以上就相当于
<result name="success" type="redirect"> /Login.jsp</result>
如何传递值呢
<result name="success" type="redirect">
<param name="location">/Login.jsp</param>
<param name="msg" >${msg}</param>
</result>
用以上方法action中必须有
ActionContext ac=ActionContext.getContext();
ac.put("msg", msg);
不能使用
HttpServletRequest ac =ServletActionContext.getRequest();
ac.setAttribute("msg",msg );
否则接受不到参数
以上是动态传至,你也可以讲${msg}替换为"要传递的内容"
Jsp页面通过EL表达式获取
${param["msg"]}
等同于
<%=request.getParameter("msg")%>
此时可能出现乱码
只要将tomcat中的confg/server.xml文件中的
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
添加编码URIEncoding="utf-8",如下
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
若是在eclipse下还要重新添加tomcat服务器