passing parameter from JSP to servlet

K

Krish

how can i pass parameter from JSP to servlet
/////in the JSP ////

<%String filechoice="1";
request.setAttribute("filechoice",filechoice); %>



//////in the servlet///
(String)request.getAttribute("filechoice"))

But I am getting null exception error....I am new to JAVA....need help
 
D

Daniel Pitts

Krish said:
how can i pass parameter from JSP to servlet
/////in the JSP ////

<%String filechoice="1";
request.setAttribute("filechoice",filechoice); %>



//////in the servlet///
(String)request.getAttribute("filechoice"))

But I am getting null exception error....I am new to JAVA....need help

I'm not really sure of your design, but a JSP is a Servlet itself, so
unless they are processing the same request, then they don't really
communicate with eachother. the request attributes are only set for
one request (in otherword, one page load from the client).
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Krish said:
how can i pass parameter from JSP to servlet
/////in the JSP ////

<%String filechoice="1";
request.setAttribute("filechoice",filechoice); %>



//////in the servlet///
(String)request.getAttribute("filechoice"))

But I am getting null exception error....I am new to JAVA....need help

First: it is a very unusual setup. Passing parameters from
servlet to JSP are way more common.

Second: it will only work using the request object if the
JSP page forward to the servlet.

All other usages would require usage of session instead of request.

Arne
 
S

Shanmuhanathan T

Krish said,on 06/11/2006 12:20 AM:
how can i pass parameter from JSP to servlet
/////in the JSP ////

<%String filechoice="1";
request.setAttribute("filechoice",filechoice); %>



//////in the servlet///
(String)request.getAttribute("filechoice"))

But I am getting null exception error....I am new to JAVA....need help

Instead of passing parameters, try using
request.getsession().setAttribute().

This would put the values in the session
for further processing.

if you still want the request to hold it, then you
would have to do a forward(), with the same request
object.

Rgds,
Shanmu.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

cactus and servlet redirection 0
JSP 0
Regarding Jsp And Java 1
Open popup from JSP - Servlet ?? 2
Servlet Question 2
Another Servlet/JSTL question 6
jsp servlet question 1
jsp/servlet target 1

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top