在test.jsp页面中:<a href="TestServlet?id=6">This is a test page</a>TestServlet类中的doGet方法中:
int id=Integer.valueOf(request.getParameter("id"));
if(id==6)
{
request.setAttribute("id", id);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
else
response.sendRedirect("Error.jsp");}index.jsp页面中:
<body>
<% String id=request.getAttribute("id").toString();
if(id==null){
%>
<h1><%=id %></h1>
<%
}
%>
</body>
为什么id是空的?页面传值失败!这是为什么?
int id=Integer.valueOf(request.getParameter("id"));
if(id==6)
{
request.setAttribute("id", id);
request.getRequestDispatcher("index.jsp").forward(request, response);
}
else
response.sendRedirect("Error.jsp");}index.jsp页面中:
<body>
<% String id=request.getAttribute("id").toString();
if(id==null){
%>
<h1><%=id %></h1>
<%
}
%>
</body>
为什么id是空的?页面传值失败!这是为什么?
解决方案 »
- 求助:HIBERNATE的关系映射问题
- 注册了一个花生壳的域名,但是没有办法访问我的jsp网站
- 怎样添加一个鼠标响应使动态生成的超链接获取一个动态生成的字符串?
- <c:forEach>不循环,只输出一次
- struts中最重要的类是哪个?
- 为什么dom保存的时候把dtd给漏了?
- 怎样用struts2实现文件上传,并将文件名插入数据库中
- jndiContext.lookup("java:comp/env/ejb/CabinHomeRemote"); 的comp/env/ejb是怎么意思
- 我有个关于XML的初级问题。
- java web,ssh框架有关于事务的处理,请教下!
- 上传文件的大小 是 由那些因素决定的?
- null值问题,请指教
%>
<h1><%=id %></h1>
<%
}
%>
自己多读几遍。
<a href="TestServlet.do?id=6">This is a test page</a>这是规范的写法。if(id==null){
%>
<h1><%=id %></h1>
<%
}
%>改成不等于 id!=null 你的条件!!!!