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

bigbluewhale 2004-09-19 09:57:05
我的用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);

...全文
162 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
okitgo 2004-11-19
  • 打赏
  • 举报
回复
帮你up
kill8108 2004-11-19
  • 打赏
  • 举报
回复
今天刚好遇到这样的问题,来搜下,为你顶下啦
bigbluewhale 2004-09-19
  • 打赏
  • 举报
回复
up

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧