Rohit Sharma
Rohit Sharma

Reputation: 103

session in jsp/struts

I have 3 jsp, jsp1..jsp & jsp2.jsp have a button name "TEST", when user click on it - he gets forwarded to Test.jsp which dynamically changes depending on which jsp user has pressed TEST.

so depending on user where he comes from, I change the logic in action class to direct the user, for that I am passing sessions.

jsp1.jsp

<input type="hidden" name="jspType" value="M" property="jspType">

jsp2.jsp

<input type="hidden" name="jspType" value="C" property="jspType">

In the action class of my Test.jsp

TestAction.java

String jspTypeVariable = (String) request.getParameter("jspType");

later down in code

if(jspTypeVariable=="M")
{
system.out.println("Magic");
}
else if (jspTypeVariable=="C")
system.out.println("Cash");

==================================

It doesnt work? Any one help

Upvotes: 1

Views: 406

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

You can't compare Strings with ==. == tests if both objects are the same instance, not if their contents is the same. Use if ("M".equals(jspTypeVariable)) instead.

Upvotes: 2

Related Questions