Struts2学习笔记
把遇到的错记下来!嗯!
1.在多业务方法处理时,有一种用!转发的方式,但是书上有错,需要在struts.xml里加一段
1 <struts> 2 <package name="strutsxx" extends="struts-default"> 3 <action name="list!*" method="{1}" class="com.sylvia.List"> 4 <result name="user">/user.jsp</result> 5 <result name="sum">/sum.jsp</result> 6 <result name="avg">/avg.jsp</result> 7 <result name="default">/default.jsp</result> 8 </action> 9 </package> 10 </struts>
2.controller 和 jsp页面的 request/session/application
controller添加
1 ServletActionContext.getRequest().setAttribute("usernameRequest",usernameRequest); 2 ServletActionContext.getRequest().getSession().setAttribute("usernameSession",usernameSession); 3 ServletActionContext.getServletContext().setAttribute("usernameApplication",usernameApplication);
jsp获取
1 <%@page isELIgnored="false" %> 2 <%@taglib uri="/struts-tags" prefix="s"%> 3 <html> 4 <body> 5 <s:property value="#request.usernameRequest"></s:property> 6 <br/> 7 <s:property value="#attr.usernameSession"/> 8 <br/> 9 <s:property value="#application.usernameApplication"/> 10 </body> 11 </html>

浙公网安备 33010602011771号