File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to send parameter from html to jsp??

 
samdeep aarzoo
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your sandeep servlet class, create a requestdispatcher object and do view.forward(req,resp) to this jsp. It will work.
 
samdeep aarzoo
Ranch Hand
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 215
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use <jsp:forward page="/s" /> action.. for forwarding the request from jsp to servlet.

Srianth
 
Aruneesh Salhotra
Ranch Hand
Posts: 167
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic