• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to send parameter from html to jsp??

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use <jsp:forward page="/s" /> action.. for forwarding the request from jsp to servlet.

Srianth
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
We noticed he had no friends. So we gave him this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic