0

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.

Subho
  • 921
  • 5
  • 25
  • 48

3 Answers3

1
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>
Santino 'Sonny' Corleone
  • 1,735
  • 5
  • 25
  • 52
1

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

Tusar
  • 759
  • 5
  • 21
0

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.

Darshan Lila
  • 5,772
  • 2
  • 24
  • 34