aspose file tools*
The moose likes JSP and the fly likes In jsp a request parameter (string value with white spaces)displayed only upto the first whitespace. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "In jsp a request parameter (string value with white spaces)displayed only upto the first whitespace." Watch "In jsp a request parameter (string value with white spaces)displayed only upto the first whitespace." New topic
Author

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

thor aniket
Ranch Hand

Joined: Jan 21, 2012
Posts: 40




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

Joined: Jan 10, 2002
Posts: 61216
    
  66

Just because this is a JSP is no excuse for sloppy HTML. Quote the value!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61216
    
  66

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

Joined: Jan 21, 2012
Posts: 40

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

Joined: Jan 10, 2002
Posts: 61216
    
  66

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

Joined: Jan 21, 2012
Posts: 40

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

Joined: Jan 10, 2002
Posts: 61216
    
  66

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

Joined: Jan 21, 2012
Posts: 40

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: In jsp a request parameter (string value with white spaces)displayed only upto the first whitespace.