一个关于request.setAttribute()的简单问题,请各位指点
设置的属性在Action中取出来是空的。
下面是我的jsp页面代码:
<%@ page contentType="text/html; charset=GBK" %>
<html:html locale="true">
<head>
<title>
jsp1
</title>
<html:base/>
</head>
<body>
<%
Float sum = new Float(10);
pageContext.getRequest().setAttribute("sum", sum);
%>
<p>
<html:form action="/untitled1Action.do" method="POST">
<html:text property="userName"/>
<br>
<html:submit property="submit" value="Submit"/><br>
<html:reset value ="Reset"/>
</html:form>
</body>
</html:html>
下面是我的Action的代码:
public class Untitled1Action extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
Untitled1ActionForm untitled1ActionForm = (Untitled1ActionForm) actionForm;
Float sum = (Float) httpServletRequest.getAttribute("sum");
System.out.println(sum.toString());
return actionMapping.getInputForward();
}
}
Float sum = (Float) httpServletRequest.getAttribute("sum"); 这句话取出来的sum就是空的,不知道为什么,请各位指教!另外我如何将上一个页面传过来得request对象里得Attribute放在当前页的Request对象里呀,是这样得么:
Float sumTotal = (Float) request.getAttribute("sumTotal");
if (sumTotal == null){
sumTotal = new Float(0);
}
pageContext.getRequest().setAttribute("sumTotal", sumTotal);
相关推荐
JSP request.setAttribute()详解及实例
主要介绍了 javascript request.setAttribute()详解及实例的相关资料,需要的朋友可以参考下
request.getParameter() 和request.getAttribute() 区别
request.getParameter() 和request.getAttribute() 区别
request.setAttribute 语句前总显示红色感叹号解决办法 HTTP Status 500 -
HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet execution threw an exception root cause java.lang.Error: Unresolved compilation problem: The method setAttribute(String, Object) in the type ServletRequest is not applicable for the arguments (String, double) y2ssh.sg.chp1.action.AddAction.execute(AddAction.java:18) y2ssh.sg.chp1.framework.Controller.doGet(Controller.java:25) y2ssh.sg.chp1.framework.Controller.doPost(Controller.java:33) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)解决办法:
Jsp的request的用法
Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法Jsp的request的用法
了解JSP中request属性的用法
很全面的了解request的属性和用法,叫你如何是使用request


Web 开发

