File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Not able to retrieve the request attribute that was set using c:set tag. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Not able to retrieve the request attribute that was set using c:set tag." Watch "Not able to retrieve the request attribute that was set using c:set tag." New topic
Author

Not able to retrieve the request attribute that was set using c:set tag.

Murali Charan
Greenhorn

Joined: May 04, 2007
Posts: 11
I am not able to retrieve the value that I have set using the <c:set> tag.

Following is the piece of code that I have in my JSP

<c:set var="page" scope="request" value="hello"/>

I am trying to retrieve the value of page in the Action class inside the execute method as follows.

request.getAttribute("page")

But this is returning me a null. I am not sure what I am missing here. Please let me know.

Thanks,
Murali
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130

Generally, when there is no attribute with the name Page in the request scope, the container is supposed to create one for you unless the value specified is Zero.

The following can be the possibilities in your case.....

1)) You can try using getAttributeNames() to find out if the required attribute is in the current request scope or not.


Regards,
Durga Prasad
Murali Charan
Greenhorn

Joined: May 04, 2007
Posts: 11
I tried this option. The attribute page is not in scope. Not sure why it isn't. Am I doing anything wrong here.

Murali
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
Post your JSP code..please...
Murali Charan
Greenhorn

Joined: May 04, 2007
Posts: 11
Hi Please find my JSP code below

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<HTML>
<HEAD>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM Software Development Platform">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="../theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE>success.jsp</TITLE>
</HEAD>
<BODY>
<P>Contract Successfully Created.</P>
Current Price : ${1+2}
<c:set var="listSize" scope="request" value="${listSize/5}"/>
<c:set var="pageStart" scope="request" value="${listSize-1}"/>
<table>
<c:forEach var="list" items="${sampleList}">
<tr>
<td>${list}</td>

</tr>
</c:forEach>
</table>
<c:forEach var="i" begin="${listSize-pageStart}" end="${listSize}" step=1>
<c:set var="page12" scope="request" value="hello"/>
<% request.setAttribute("page12","hello"); %>
<html:link action="contractSearch.do">${i}</html:link>
Page:${page}
<c:set var="listSize" scope="request" value="${listSize-1}"/>
</c:forEach>
</BODY>
</HTML>


I think there a very simple problem here. Because I am not able to retrieve the page12 attribute even if I put it in the request using scriplet. Not sure were I am going wrong

Thanks
Murali
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Originally posted by Murali Charan:
I am trying to retrieve the value of page in the Action class inside the execute method as follows.
What execute method? Where is this method? What relationship does it have with the request in which the JSP is rendered?
Marimuthu Madasamy
Ranch Hand

Joined: Jun 07, 2007
Posts: 72

If i understand your problem, I hope you want to access the 'page12' attribute inside 'contractSearch' action called through the link in JSP. It is not possible since whenever you click a link it will be sent as a new 'request'. Whatever request attributes you set in JSP using JSTL or Scriptlet are bound to the request object which is there when the JSP is being rendered. After the JSP is rendered the request object is destroyed. After that if you click the link, a new request object is created. Thats why you cant get the 'page12' request attribute inside 'contractSearch' action.

Hope this helps.
[ May 30, 2008: Message edited by: Marimuthu Madasamy ]

- Marimuthu Madasamy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to retrieve the request attribute that was set using c:set tag.