Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retreving values in a jsp

Status
Not open for further replies.

ilarum

Programmer
Aug 25, 2003
13
DE
Hi,
Assume that I have a JSP with input fields. Also I have a submit button which when clicked takes you to another JSP. But the need is here to ensure that when I click the values from the i/p field (entered by the user) should be retrived and stored in a 2d array. And I need to pass this 2D array to the other JSP. how can i do this.

With Regards
Murali

 
I would suggest you to use a servlet.Modify the action of your form to the name of the servlet you are about to write,take the variables by request.getParameter(<fields>) method, store these data in an array (you want it so),put this array in your session attribute then simply use response.sendRedirect(&quot;your second jsp&quot;). In your second jsp you can retrieve your array by session.getAttribute method.

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
 
Hi,
Assume that I dont want to use a intermediate servlet/jsp. Then how do you achieve this. Do let me know.

With Regards
Murali
 
That doesn't make much sense to me.You are pointing your action to your new jsp then the &quot;storing process&quot; only can take place in your new jsp.In your second jsp, you could fill your array with your data submitted by jsp1.

Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
 
Hi,
Is not possible technically.

With Regards
Murali
 
Hi,
Here is the code that can achieve this objective.
//First JSP

<%@ page import = &quot;java.util.Hashtable&quot; %>
<html>

<%
if(request.getParameter(&quot;name&quot;) != null && request.getParameter(&quot;email&quot;) != null)
{
Hashtable ht = new Hashtable();
ht.put(&quot;name&quot;, request.getParameter(&quot;name&quot;));
ht.put(&quot;email&quot;, request.getParameter(&quot;email&quot;));
session.setAttribute(&quot;MyHashTable&quot;, ht);
%>
<jsp:forward page=&quot;second.jsp&quot; />
<%
}
else
{
%>

<form method = &quot;post&quot; action = &quot;first.jsp&quot;>
<input type = &quot;text&quot; name = &quot;name&quot;>
<input type = &quot;text&quot; name = &quot;email&quot;>
<input type = &quot;submit&quot; value = &quot;Click&quot;>
</form>
<% } %>
</html>

//Second JSP

<html>
<%@ page import = &quot;java.util.*&quot; %>
<%
Hashtable ht = (Hashtable) session.getAttribute(&quot;MyHashTable&quot;);
Enumeration enum = ht.keys();
String concat = &quot;&quot;;
while(enum.hasMoreElements())
{
Object temp = enum.nextElement();
concat += ht.get(temp.toString());
}
%>
<head>
<h1>Second JSP</h1>
</head>
<body>
<h1> Welcome </h1>
<%= concat %>
</html>

This code works. But there is problem. After I click on the button My URL shows still one.jsp and not second.jsp.

Why is that.

With Regards
Murali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top