• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP - Passing a string through URL

 
Gajan Raj
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I am having trouble passing a string from JSP through URL to another JSP. For some reason the string is null I have attched the relevant bits of code below... Please help...

First JSP
--------------------------
...
<%
List aList = new LinkedList();
String createEmployeeURL = "MaintainEmployee.jsp?pageSource=Create&employees="+aList;
%>
<a href=<%= createEmployeeURL %>>
<b>Create A New Employee</b>
....
The LinkedList is empty. That is fine. its the pageSource String I am having difficulty with.
---------------------------------
Second JSP
--------------------------------
<jsp:useBean id="employees" class="java.util.LinkedList" scope="request"/>
<jsp:useBean id="pageSource" class="java.lang.String" scope="request"/>
....
<%
String pageMode = (String)request.getAttribute("pageSource");
%>
For some reason String pageMode is empty....
Would appreciate anyhelp on this matter...
Regards,
Gajan
 
maneesh subherwal
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try request.getParameter("pageSource") instead.
Thanks,
Maneesh
 
Gajan Raj
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Manesh...That worked.
 
Kaustubh Patil
Ranch Hand
Posts: 164
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gajan Raj:
Thanks Manesh...That worked.

Gajan,
Just to add to the discussion. The problem why you were not getting the variable using the <usebean> tag is :
Whenever you instantiate a variable using the usebean tag and request as a scope it particulary looks for the objects in the requests. The equivalent of this would be request.getAttribute(). But what you are doing now is passing the params by query string. So the values that you are passing are not accessed as objects in the requests but simply as name-value pairs.
So these can be accessed using request.getParameter().
-Kaustubh
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic