Reputation: 923
I send some values from one jsp page to another using link like -
<a href="get.jsp?value=Mobile">Mobile Phones</a>
In the nex page i get the value using request.getParameter like-
if (request.getParameter("value") == "Mobile") {
electronicType = "Mobile Phone";
}
Then I want to make another link using the value like-
<a href="mob.jsp">electronicType</a>
Instead of electronicType I want the value of electronicType. But I can not get the value of electronicType. please somebody help me.
Upvotes: 0
Views: 61
Reputation: 1753
if (request.getParameter("value") == "Mobile") {
electronicType = "Mobile Phone";
}
This is wrong,for comparison in java you need to use .equals
So your code should be
if (request.getParameter("value").equals("Mobile")) {
electronicType = "Mobile Phone";
}
==
you can use for number or if you want to check if an object is null
For example if(object == null)
But for Strings you need to use .equals
Read the SO post that Sotirios Delimanolis has suggested
And in your <a href="mob.jsp">electronicType</a>
use JSP tags like this
<a href="mob.jsp"><%=electronicType%></a>
Or a better way
<a href="mob.jsp"><c:out value="${electronicType}" /></a>
Upvotes: 1
Reputation: 769
AS suggested by @Sanito use equals() instead of = to comparing String
<a href="mob.jsp"><c:out value="${electronicType}" /></a>
used JSTL to print value
Upvotes: 1
Reputation: 5868
First of all note that you are not comparing two strings right way. Use equals() method.
For electronicType, add a session varible for electronicType and use it whenever you need from session. Otherway is to add it in the url.
Upvotes: 0