Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Space in Session object

 
Ken Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sloppy HTML. Be sure to put quotes around each and every attribute in your HTML template text.
 
Ken Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry - actually, it was a bad copy/paste. That line should be:

<%=uName %>
 
Ken Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgot to mention - adding explicit quotes around the field worked.

thanks, k
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic