954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

String object and string literal probs jsp

I have a log in page for users, which if the login name is valid takes user name and puts it into

a session.setAttribute(“user”, String);

the user then gets redirected a userspage.jsp.

At that page I can get the “user” using :

<% getAttribute = (String)session.getAttribute("user"); %>
the user is <%= getAttribute %>

I can easily add a suffix String alluser = user+ .html

I want to use it in some text but obviously this would equate to literally alluser getting an can’t find alluser page. I want to use the value of alluser with a method which replaces

luddite
Newbie Poster
3 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

You mean that this:

<% 
String link = "";
String user = (String)session.getAttribute("user"); 
if (user!=null) {
  link = user + ".jsp";
} else {
  // do something else since the user is not in the session
}
%>

<a href = "<%=link%>" > some text </a>


Is not what you want?

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

javaAddict

exactly - thanks very much it was the "<%=link%>" i was having trouble with , its working just tested on tomcat; some how before it wasn't - if off for a calamine tea!

luddite
Newbie Poster
3 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You