aspose file tools*
The moose likes Servlets and the fly likes Calling servlet from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling servlet from JSP" Watch "Calling servlet from JSP" New topic
Author

Calling servlet from JSP

prakash muthu
Ranch Hand

Joined: Sep 06, 2000
Posts: 75
Hi
I'm calling servlet from and i'm sending some data also. but i couldn't get the value from servlet. I got a value "null" only.
Code from JSP:
<jsp:forward page="/servlet/senthil">
<jsp aram name="prak" value="Prakash">
</jsp:forward>
code from Servlet :
String gh=req.getParameter("prak");
out.println("Value from JSP "+gh);
Check it out and let me know the solution.
TIA
With regards
Prakash

Prakash.M<BR>Bangalore- India<BR>(prakashem@rediffmail.com)
Kapil Agrawal
Greenhorn

Joined: Nov 03, 2000
Posts: 11
Try this in your jsp file:
<FORM METHOD="POST" ACTION="/servlet/senthil">
<INPUT TYPE="TEXT" NAME="prak" VALUE="Prakash">
<INPUT TYPE="SUBMIT" VALUE="Send">
</FORM>
prakash muthu
Ranch Hand

Joined: Sep 06, 2000
Posts: 75
Dear Kapil,
Thanks for your reply. Your has to work, but what probelm with my code. Is there any error or its totally mistake. let me know the details of how to call a servlet from JSP.
with regards
Prakash
Kapil Agrawal
Greenhorn

Joined: Nov 03, 2000
Posts: 11
Dear Prakash,
I should have added little explanation for my recommendation. Well, jsp:forward lets you forward the request to another page. It has a single attribute, page, which consists of a URL. It is not capable of carrying a variable value with it. So, if you need to transfer any value and the value is coming from user input, then a 'form' should serve the purpose. If the value is coming from some internal calculation of some java bean, then you can use jsp:usebean, setProperty and getProperty to modify and retrieve bean properties.
Hope it helps.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Don't forget that you can also use query parameters in a URL. SO your original example might be re-coded as:
JSP:

Servlet:


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Kapil Agrawal
Greenhorn

Joined: Nov 03, 2000
Posts: 11
Yep, you got the right nerve.
prakash muthu
Ranch Hand

Joined: Sep 06, 2000
Posts: 75
Hi frank
How it will work. It will search like a sevlet class in the name of senthil?prak=prakash. I got a error like that only
then what is the use of jsp aram tag.
I'm using java webserver 2.0.
let me know more details.
with regards
Prakash
Gopal Rao
Greenhorn

Joined: Jun 06, 2002
Posts: 1
Hi Prakash,
I am not sure if you ever solved the problem. It is simple: you missed the terminating slash character for the "param" tag.
<jsp:forward page="/servlet/senthil">
<jsp aram name="prak" value="Prakash" />
</jsp:forward>
I put it after "Prakash" as above and tested it. It works file.
Gopal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling servlet from JSP