0

//styleDetail.jsp

<html>   
<jsp:useBean id="productView" scope="request" class="com.view.ProductView" />   
....   
 <% List result = productView.getProductList();   
Iterator it = result.iterator();   
while(it.hasNext()){ %>   
<tr>   
<td><input type="checkbox" name="id"></td>   
<% List temp = (List) it.next();   
Iterator it1 = temp.iterator();   
while(it1.hasNext()) {   
Object obj = it1.next();   
request.getSession().setAttribute("value",obj); %>   
<td><a href="ProductController?selectedValue=link">   
<% out.print(obj); %>   
</a></td><% } %>   
</tr><% } %>   
.....   
</html>

//ProductController.java

....   
String selectedValue = request.getParameter("selectedValue");   
if(selectedValue!=null)   
{   
if(selectedValue.equals("link"))   
{   
Object obj = request.getSession().getAttribute("value");   
System.out.println(obj);   
response.sendRedirect("productResult.jsp");   
}    
}   
...

When i run the above code, a table is displayed with links. when i click on the link, the control is passed to the servlet 'ProductController' and i want to get the value of the link i have clicked.... If suppose the link clicked is 'ABC', this value should be read in the servlet..When i run the above code, the value of 'obj' is printed as 4 irrespective of any link i click in the jsp. Kindly help with a solution.....

2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by gaya123
0

Your session attribute for value will be 4 since only one value is stored in an attribute, in the loop you are overwriting teh value, by the next number in the loop.

To get teh value of the link clicked, u can pass the value in the url so the url could look somehting like this:

<a href="ProductController?selectedValue=link&selLink="<%=obj%>>

then use request.getParameter to get the value of selLink

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.