This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Space in Session object" Watch "Space in Session object" New topic
Author

Space in Session object

Ken Clark
Greenhorn

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=http://69.250.174.31/nfl/index.html\">");
response.getWriter().close()
; }
%>
...
...
...
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?

k
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ken Clark
Greenhorn

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

<%=uName %>
Ken Clark
Greenhorn

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

thanks, k
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Space in Session object