variables in hidden field of form...

Posted on 2003-02-21
Medium Priority
Last Modified: 2010-03-31
On a JSP page I have the following:

String inputtedName = "Some Text";

<input type='hidden'  value=" + inputtedName + " name='enteredName'>

When I go to  extract the value from enteredName on the following JSP page with:


out.println("The Name is:" + getTheName);

I get only part of the original value of inputtedName. I only get the first word. So in this case it would be the word "Some".

In ordered to compensate for this I have had to use an invislbe  textarea instead of the standard hidden field which doesnt seem to cause the same problems.

Is there a way around having to use a textarea?

Question by:coincidence
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Venci75 earned 150 total points
ID: 7993188
try quoting the value:
<input type="hidden"  value=" <%= inputtedName %> " name="enteredName">

LVL 86

Expert Comment

ID: 7993191

<input type=\"hidden\"  value=\"" + inputtedName + "\" name=\"enteredName\">

Expert Comment

ID: 7993612
u try to use Venci75 way u will get
 String inputtedName = "Some Text";

<input type=hidden  value=<%= inputtedName%> name=enteredName>

while retreiving


out.println("The Name is:" + getTheName);

now it won't give any error.


Expert Comment

ID: 7994282
Actually the above is correct but I think you still need the quotation marks.

One approach would be like so:


    String inputtedName = "Some Text";

<input type=hidden  value="<%= inputtedName%>" name="enteredName">

On Next page:

    String getTheName = (request.getParameter("enteredName")!=null)?request.getParameter("enteredName").trim():"";
<P>The name is: <%=getTheName%></P>


    String getTheName = (request.getParameter("enteredName")!=null)?request.getParameter("enteredName").trim():"";
out.print("The name is: "+getTheName);


Author Comment

ID: 7998717
Thanks everyone for your help. I think VENCI75 was the closest. I relised after asking the question that since the variable contained spaces it needed to be inbetween  quotes of some sort in the HTML part so that it could be read as all one item, thats why the word SOME was only appearing. Thanks again.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question