[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 776
  • Last Modified:

passing HTML value to JSP

Frds,
   I want to pass selected value from HTML(may be Text or drop down)
to JSP code ?
Thanks in advance ...
karan
0
Manish
Asked:
Manish
  • 8
  • 6
  • 5
2 Solutions
 
hongjunCommented:
You can always do this

<form action="page2.jsp" method="post">
<input type="text" name="Text1">
<input type="submit">
</form>


in your page2.jsp, you do this to get the text value
    request.getParameter("submit");


hongjun

0
 
hongjunCommented:
to print out the text, you do this

out.println(request.getParameter("Text1));


hongjun
0
 
Nick_72Commented:
You will have to resubmit the page and retreve the parameter.

for example:

<%
  if (request.getParameter("myTextField") != null) {
%>   alert('Parameter found: <%=request.getParameter("myTextField")%>');
<%}
%>

<form method="post" name="myform" action="#">
  <input type="text" name="myTextField" onBlur="this.form.submit();">
</form>

/Nick
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
hongjunCommented:
ignore my first comment on "request.getParameter("submit");"...
0
 
ManishLeadAuthor Commented:
I want to use on same page without submitting ?
Is it possible?
0
 
hongjunCommented:
For the same page, you can always use METHOD=get and submit to the same page.
To retrieve it, you do the same thing.
0
 
hongjunCommented:
<form method="get">
...
</form>
0
 
Nick_72Commented:
>>I want to use on same page without submitting ?
>>Is it possible?

I'm afraid not.
0
 
ManishLeadAuthor Commented:
But I have to remember all other selected value..
Is it possible to pass the value to javascript and use in
java code of jsp?
0
 
Nick_72Commented:
no it's not, since javascript is executed on the client, while all jsp code is processed on the server. That is why you have to submit the page so the server gets the values.
0
 
ManishLeadAuthor Commented:
So without sumit it is not possible?
0
 
Nick_72Commented:
that's right
0
 
ManishLeadAuthor Commented:
Thanks hongjun and Nick..
U both cleared my problem...
There should be sharing points among u...
karan
0
 
Nick_72Commented:
There is a feature to share points ;) not now though, it's too late since it's already accepted.
No problem.

/Nick
0
 
hongjunCommented:
0
 
hongjunCommented:
@ee_ai_construct

OK. I am fine with the split if the questionner replies.

hongjun
0
 
ManishLeadAuthor Commented:
How to share points ,Sorry I dont know?
0
 
hongjunCommented:
Yeah.
0
 
Nick_72Commented:
Thank you guys, I appreciate it :)

/Nick
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now