Giorgi Gvimradze
Giorgi Gvimradze

Reputation: 2129

How to compare string in JSP

I'm trying to detect the name of the page index.jsp and compare it with the one I need.

<% 
    String uri = request.getRequestURI();
    String pageName = uri.substring(uri.lastIndexOf("/")+1);
    if (pageName=="index.jsp"){out.println(pageName); }
    out.println(pageName);
%>

It outputs - index.jsp, but does not do it twice, neither without out.println() functuion.

Upvotes: 3

Views: 1687

Answers (1)

Deedar Ali Brohi
Deedar Ali Brohi

Reputation: 265

String pageName = uri.substring(uri.lastIndexOf("/")+1); if (pageName.equals("index.jsp")){out.println(pageName); }

comparing string values in jsp you have to use .equals("") method

Upvotes: 3

Related Questions