how can i cal servlet from jsp page?how can i pass
variablesfrom the jsp that servlet can access?



how can i cal servlet from jsp page?how can i pass variablesfrom the jsp that servlet can access?..

Answer / ranjani

By using JSP forward attriputes within the html tag we can
just forward our page to servlet.or by using
response.sendRedirect()method we can call servlet page.
for example
-----------
<jsp:forward page="/relativepath/YourServlet" /> or
response.sendRedirect("http://path/YourServlet").

We can also pass the parameters in the same way to the
servlet
for example
-----------
<jsp:forward page=/relativepath/YourServlet>
<jsp:param name="name1" value="value1" />
<jsp:param name="name2" value="value2" />
</jsp:forward>
You may also pass parameters to your servlet by specifying
response.sendRedirect("http://path/YourServlet?
param1=val1").

Is This Answer Correct ?    11 Yes 1 No

Post New Answer

More Core Java Interview Questions

wHAT IS DEFAULT SPECIFIER IN JAVA wHAT IS DEFAULT CONSTRUCTOR IN JAVA wHAT IS DEFAULT METHOD IN JAVA

12 Answers   IBM,


What is busy spin, and why should you use it?

0 Answers  


java program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

7 Answers   HCL, Wipro,


What is arrays sort in java?

0 Answers  


whats the diff between jsp and servlets?

9 Answers   HCL, TCS,






What does compareto () do in java?

0 Answers  


What will happen inside init() in servlet. my interviewer asked servlet lifecycle. i said "once servlet is loaded in to memory init() will be called which performs servlet initialization " . Again interview asked what values will be initialized . what is difference between init() and init(ServletConfig config).

2 Answers   Infinite Computer Solutions, TCS,


Which sorting algorithm is in place?

0 Answers  


Can a main method be declared final?

0 Answers  


What are unchecked exceptions in java?

0 Answers  


What is a class reference?

0 Answers  


What is java jit compilers?

0 Answers  


Categories