Forums Register Login

Calling servlet from JSP

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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>
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Don't forget that you can also use query parameters in a URL. SO your original example might be re-coded as:
JSP:

Servlet:
+Pie Number of slices to send: Send
Yep, you got the right nerve.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 57946 times.
Similar Threads
Error passing data from jsp to servlet
Servlet and JSP interaction
calling servlet from jsp
Form Variables
Calling servlet from jsp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:29:31.