Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getParameter returns truncated string  RSS feed

 
Reed Peters
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried everything/searched everywhere and can't come up with an answer. Hope someone can give me a clue...
I have and application that is doing a customer name search. It starts with an HTML Form that Posts the user entered name to search by. A controller servlet receives the request an gets the name to search by with a request.getParameter("custName"); This works fine. The servlet performs the search, gets the results, stores them in the session, and requestDispatches.forwards to a JSP. The JSP shows the results and everything is good. However, the JSP also shows the original name that the User searched with. It uses <%= request.getParameter("custName") %> to retrieve it. The problem is that it truncates the search request name at the first space entered. For example, if the user enters APPLE COMPUTER only APPLE appears in the JSP's "new" search field. The search itself works fine. Just before I dispatch to the JSP I print out request.getParameter("custName") and it shows the complete name (APPLE COMPUTER). Any Ideas?
I have tried everything I can think of. I even switched to storing it in the session, but got the same results. Here's the JSP code to show the name:
<TD width="351">or By Name:<INPUT size="31" type="text" maxlength="25" name="custName" value=<%=request.getParameter("custName")%>></TD>
Thanks,
Reed Peters
Reed@cm-inc.com
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like somewhere along the path that this paramter is taking, it is not getting properly URL-encoded. That's where I'd sniff around first.
hth,
bear
 
Reed Peters
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am actually not encoding the customer name at all. The HTML form is storeing it in the request, the servlet is retriving it, using it to perform the search, then fowarding the (same) request on to the JSP. When the JSP retrieves the customer name it is truncated at the first occurance of a space in the name. In fact, when I enter the name as AT&T/REED@HELP"PLEASE it returns it just fine. Even with all the &/@" characters. Surely storing strings parameters into a request or a session, don't need URL encoding. Is there some other encoding you are talking about?
[ September 25, 2002: Message edited by: Reed Peters ]
[ September 25, 2002: Message edited by: Reed Peters ]
 
Shawn Bayern
Author
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blanks (" ") are not valid in URLs. You must encode the parameter. If you use the standard <cut> tag instead of a scripting element, the information will be encoded automatically.
 
Reed Peters
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem seems to be in the Text Box's value= attribute and the usage of a javascript expression to prime it. Here's a sample JSP that illustrates the problem:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META name="GENERATOR" content="IBM WebSphere Studio">
<TITLE>testJSP.jsp</TITLE>
</HEAD>
<BODY>
<% String stringField = "Hello There!"; %>
<%=stringField%>
Input Text Box:<INPUT size="30" type="text" maxlength="30" name="aField" value=<%=stringField%>>
</BODY>
</HTML>
Notice that the stringField is set to "Hello There!" and that it is used to prime the value in the Text box using a javascript expression. However, only "Hello" shows up in the text box.
Does this work differently for anyone else? Is there anyway to dynamically prime the text box's value with the complete string with imbedded spaces?
HELP!
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There might be some settings in the browser that is causing this behavior. I know I had something similar. I unchecked the use http1.1 proxy setting in under the options/advanced tab in the browser and it worked okay.
 
Reed Peters
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone. The fix was to add single quotes on the VALUE= attribute.
Input Text Box:<INPUT size="30" type="text" maxlength="30" name="aField" value='<%=stringField%>'>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!