File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes how to send parameter from  html  to jsp?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "how to send parameter from  html  to jsp??" Watch "how to send parameter from  html  to jsp??" New topic
Author

how to send parameter from html to jsp??

samdeep aarzoo
Ranch Hand

Joined: Jun 09, 2005
Posts: 160
i want to send parameter from html form to jsp than what should i do ?
i know how to send parameter in servlet from html, i m trying for jsp.
i have done that much

index.html

<html><body>
<form action = "s">
first parameter : <INPUT TYPE ="TEXT" NAME = "param1"><br>
second parameter : <INPUT TYPE ="TEXT" NAME = "param2"><br>
third parameter : <INPUT TYPE ="TEXT" NAME = "param3"><br>
<INPUT TYPE ="submit"
</form action>
</html></body>


sandeep.jsp




web.xml

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">


<servlet>
<servlet-name>webdav</servlet-name>
<servlet-class>sandeep</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webdav</servlet-name>
<url-pattern>/s</url-pattern>
</servlet-mapping>
</web-app>

what changes should i do in web.xml file


i m getting answer
Reading Three Request Parameters
param1: null
param2: null
param3: null

please tell the changes that i should do
Harish Yerneni
Ranch Hand

Joined: Sep 15, 2004
Posts: 94
In your sandeep servlet class, create a requestdispatcher object and do view.forward(req,resp) to this jsp. It will work.


SCJP 1.4 | SCWCD 1.4 | SCJD (WIP)
samdeep aarzoo
Ranch Hand

Joined: Jun 09, 2005
Posts: 160
yes its working
can i do without request dispatcher code in servlet class??

how can we give paramter to jsp directly without sevlets???
as jsp can also become servlet object after compiling
Mat Williams
Ranch Hand

Joined: Jul 20, 2005
Posts: 215
Hi,

just change your html file from
<html><body>
<form action = "s">
first parameter : <INPUT TYPE ="TEXT" NAME = "param1"><br>
second parameter : <INPUT TYPE ="TEXT" NAME = "param2"><br>
third parameter : <INPUT TYPE ="TEXT" NAME = "param3"><br>
<INPUT TYPE ="submit"
</form action>
</html></body>

to
<html><body>
<form action = "./sandeep.jsp">
first parameter : <INPUT TYPE ="TEXT" NAME = "param1"><br>
second parameter : <INPUT TYPE ="TEXT" NAME = "param2"><br>
third parameter : <INPUT TYPE ="TEXT" NAME = "param3"><br>
<INPUT TYPE ="submit"
</form action>
</html></body>

Make sure that the jsp file is in the same directory as the html file and all should work.


Mat
samdeep aarzoo
Ranch Hand

Joined: Jun 09, 2005
Posts: 160
yes its working

how can i dispatch request from jsp to servlets ???
what changes should i have to do in jsp ?

as earlier i have already dispatch the request from servlets to jsp
servlet code
sandeep.java

[ August 17, 2005: Message edited by: sandeep mittal ]
okkadu privt
Ranch Hand

Joined: Feb 07, 2005
Posts: 30
Use <jsp:forward page="/s" /> action.. for forwarding the request from jsp to servlet.

Srianth
Aruneesh Salhotra
Ranch Hand

Joined: May 12, 2004
Posts: 167
Make the changes in web.xml to not have a servlet-class but instead have a jsp-file tag.
Interestingly you should not get the values as null, as it seems the control is going to the servet.
sing
Ranch Hand

Joined: Nov 29, 2001
Posts: 121
Originally posted by Mat Williams:
Hi,

just change your html file from
<html><body>
<form action = "s">
first parameter : <INPUT TYPE ="TEXT" NAME = "param1"><br>
second parameter : <INPUT TYPE ="TEXT" NAME = "param2"><br>
third parameter : <INPUT TYPE ="TEXT" NAME = "param3"><br>
<INPUT TYPE ="submit"
</form action>
</html></body>

to
<html><body>
<form action = "./sandeep.jsp">
first parameter : <INPUT TYPE ="TEXT" NAME = "param1"><br>
second parameter : <INPUT TYPE ="TEXT" NAME = "param2"><br>
third parameter : <INPUT TYPE ="TEXT" NAME = "param3"><br>
<INPUT TYPE ="submit"
</form action>
</html></body>

Make sure that the jsp file is in the same directory as the html file and all should work.


Mat



You can also do as below in your jsp page.

<form action = /shop/LoginServlet">

also, below config in web.xml if you using tomcat as Servlet/JSP container

<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.shop.admin.LoginServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
samdeep aarzoo
Ranch Hand

Joined: Jun 09, 2005
Posts: 160
hi can anyone help me

if i want to add records
if i press add two times in my html form and give parameter
a b c and d e f respectively,
output must be like this as below.
i have given my code above that i have done
please help me
output


param1: a
param2: b
param3: c

param1: d
param2: e
param3: f
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to send parameter from html to jsp??