?
Solved

variables in hidden field of form...

Posted on 2003-02-21
5
Medium Priority
?
245 Views
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:

getTheName=request.getParameter("enteredName");

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?

0
Comment
Question by:coincidence
5 Comments
 
LVL 9

Accepted Solution

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

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 7993191
Try

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

Expert Comment

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

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

while retreiving

getTheName=request.getParameter("enteredName");

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


now it won't give any error.

0
 
LVL 1

Expert Comment

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

One approach would be like so:

On JSP:

<%
    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>

or:

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

0
 

Author Comment

by:coincidence
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

571 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