双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

一个关于request.setAttribute()的简单问题,请各位指点

bigbluewhale bigbluewhale 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我的用struts做了一个简单的例子,但是遇到了这样的问题,我在jsp页面中用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()详解及实例的相关资料,需要的朋友可以参考下

weixin_38608873

request.getParameter() 和request.getAttribute() 区别

request.getParameter() 和request.getAttribute() 区别

wbdban

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)解决办法:

zhp258

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的用法

lyqidao

了解JSP中request属性的用法

很全面的了解request的属性和用法,叫你如何是使用request

raomi
评论 3
收藏 已收藏
分享
返回顶部
bigbluewhale
Web 开发 81,108 成员 341,721 内容