File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Space in Session object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Space in Session object" Watch "Space in Session object" New topic

Space in Session object

Ken Clark

Joined: Aug 02, 2004
Posts: 11
I've got a servlet that sets some session data:

private void updateSessionData(HttpServletRequest request, int userLevel){
HttpSession session = request.getSession( true );
session.setAttribute( "userName", userName );
session.setAttribute( "password", password );
session.setAttribute( "groupName", groupName );
session.setAttribute( "userLevel", userLevel );

And a .jsp page that displays the userName:

String uName = (String)session.getAttribute( "userName" );
if ( uName == null ){
response.getWriter().println( "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=\">");
; }
Name: <INPUT maxLength=25 size=25 name=name
disabled="disabled" value=
<%=uName" )%>

There seems to be a problem if the userName has a space in it. If the userName is "Ken F.", the page is rendered thusly:

<input maxlength="25" size="25" name="name" disabled="disabled" value="Ken" f="">

What's going on?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Sloppy HTML. Be sure to put quotes around each and every attribute in your HTML template text.

[Asking smart questions] [About Bear] [Books by Bear]
Ken Clark

Joined: Aug 02, 2004
Posts: 11
Sorry - actually, it was a bad copy/paste. That line should be:

<%=uName %>
Ken Clark

Joined: Aug 02, 2004
Posts: 11
Forgot to mention - adding explicit quotes around the field worked.

thanks, k
I agree. Here's the link:
subject: Space in Session object
It's not a secret anymore!