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.

2
  • 1
    First, read this. Then use request attributes and EL. Commented Jul 3, 2014 at 7:07
  • reply so that v know you have got ur answer and v can close this question Commented Jul 3, 2014 at 7:26

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.