• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In jsp a request parameter (string value with white spaces)displayed only upto the first whitespace.

 
thor aniket
Ranch Hand
Posts: 40
Hibernate jQuery
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



In this JSP, I've send request parameters from an another JSP page via javascript using window.location.replace() function.

I want to display that request parameter in this jsp page in a text-box.

But its showing only a part of the string up to the first white-space only. remaining string is got trimmed.

What might be the cause of this problem?

e.g. if designation="software engineer" then it is displaying in the text box only "software", and not " "(space) and "engineer"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64181
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because this is a JSP is no excuse for sloppy HTML. Quote the value!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64181
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, in 2012 you should be using the EL, not scriptlets.

<input type="text" name="designation" value="${param.designation}">

Also, there should never be an </input>. Input elements are self-closed in XHTML, and doesn't need closing at all in HTML.
 
thor aniket
Ranch Hand
Posts: 40
Hibernate jQuery
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear Bibeault for the reply. Using "${param.designation}" displaying whole string with whitespaces too. My problem is solved.
I'll be using JSP ELs more than scriptlets. Thanks again.!!! :))
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64181
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the problem was just the lack of quoting. Be sure to quote all your attribute values. But using the EL and JSTL is modern practice. Scriptlets have been discredited for 10 years now and should no longer be used an any new JSP page.
 
thor aniket
Ranch Hand
Posts: 40
Hibernate jQuery
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I've read they're hard and complicated to maintain. But as I have been in learning process of JSP, I tried scriptlets. But now onwards it'll be just EL and JSTL as I learn them. Anyway, its as always your help comes to my aid. Thank you Bear Bilbeault.!! :))
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64181
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thor aniket wrote:But as I have been in learning process of JSP, I tried scriptlets

Bad idea. Why learn the wrong way to do things first?

When learning Java, would you start by using Java 1.1? Or modern Java 6 or 7?

Learn the JSTL and EL first as they are the modern way to create JSP pages. Then, if you find that you need to learn scriptlets in order to support legacy pages, learn that last, after you firmly understand how to do things the right way.
 
thor aniket
Ranch Hand
Posts: 40
Hibernate jQuery
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Bear Bileault!! You're absolutely right..!! I have to master right and standard things( EL and JSTL)first and would learn some legacy ways(Scriptlets) in the last. Actually Head first Servlet and JSP has a couple of pages on scriptlet topic on the way before actual EL and JSTL starts. But I haven't started to read EL and JSTL chapters. So I had been finding solutions just from scriptlets way( Ignoring Author's warning). But, now, I have to finish EL and JSTL them as soon as possible. and then I will be using EL n JSTL only. Thank you for your kindly mentoring.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic