prasad2000
asked on
Servlet Redirection.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
//Invoke the otherservlet and pass the requestobject as an argument to it
//for ex invoke a servlet called MyServlet(request).
}
can u please put the relevant code needed in the place of comments in the above code.
Thx in advance
ASKER
Also
I want to invoke Myservlet as an HTTPS request.
That means
http://servlet/MyServlet(request)
The above request should be made
I want to invoke Myservlet as an HTTPS request.
That means
http://servlet/MyServlet(request)
The above request should be made
ASKER
sorry in the above comments https is missing
https://servlet/MyServlet(request)
https://servlet/MyServlet(request)
ASKER
will try that option and let u know if it works
ASKER
Objects..
ur code invokes Myservlet but I also want my requestobject to be passed to Myservlet..
ur code invokes Myservlet but I also want my requestobject to be passed to Myservlet..
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
javax.servlet.http.HttpSes sion session = request.getSession();
javax.servlet.ServletConte xt aContext = session.getServletContext( );
javax.servlet.RequestDispa tcher rd = aContext.getRequestDispatc her("https://servlet/MyServlet");
rd.forward(request, response);
}
doesn't it work?
{
javax.servlet.http.HttpSes
javax.servlet.ServletConte
javax.servlet.RequestDispa
rd.forward(request, response);
}
doesn't it work?
> but I also want my requestobject to be passed to
> Myservlet..
don't think u can do it if you want to switch to https.
the browser needs to resend the request.
Perhaps you could store the relevant parts of the request in the session, or add then to the request url.
> Myservlet..
don't think u can do it if you want to switch to https.
the browser needs to resend the request.
Perhaps you could store the relevant parts of the request in the session, or add then to the request url.
just try to user
response.sendRedirect("https://yourserver/servlet/MyServlet?" + request.getQueryString()):
this won't work when using multipart forms but for simple parameters it should work out.
response.sendRedirect("https://yourserver/servlet/MyServlet?" + request.getQueryString()):
this won't work when using multipart forms but for simple parameters it should work out.
ASKER
am not able to compile the above code.
getting the error in the below line.
javax.servlet.ServletConte xt aContext = session.getServletContext( );
There is no getServletContext() method in the session object.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
javax.servlet.RequestDispa tcher rd = request.getRequestDispatch er("https://servlet/MyServlet");
rd.forward(request, response);
}
I tried the above code.
and am getting the below exception when i run the program
ServletInstan X Uncaught service() exception thrown by servlet {0}: {1}
"frontservlet"
javax.servlet.ServletExcep tion: javax.servlet.ServletReque st: method getRequestDispatcher(Ljava /lang/Stri ng;)Ljavax /servlet/R equestDisp atcher; not found
at javax.servlet.ServletExcep tion.<init >(ServletE xception.j ava:73)
at
getting the error in the below line.
javax.servlet.ServletConte
There is no getServletContext() method in the session object.
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
javax.servlet.RequestDispa
rd.forward(request, response);
}
I tried the above code.
and am getting the below exception when i run the program
ServletInstan X Uncaught service() exception thrown by servlet {0}: {1}
"frontservlet"
javax.servlet.ServletExcep
at javax.servlet.ServletExcep
at
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
squeezeMe> I already mentioned trying that.
are you sure ...
as far as i understood you were trying to accomplish this using the RequestDispatcher, but what you want won't be working with the RequestDispatcher... you're leaving the ServletContext when you want to call that https resource.
anyway, this is what I thought you tried:
javax.servlet.RequestDispa tcher rd = request.getRequestDispatch er("https://servlet/MyServlet");
rd.forward(request, response);
this is what i suggested:
don't use the ServletContext not the RequestDispatcher...
just use response.sendRedirect...
response.sendRedirect("https://www.microsoft.com?" + request.getQueryString());
i testest my solution on tomcat 4.x and orion successfully.
which server are you using. the error you're getting is quite strange...
so either i dont understand your problem, or you did not try my solution and mixed it up with some ServletContext and RequestDispatcher action...
cheers
as far as i understood you were trying to accomplish this using the RequestDispatcher, but what you want won't be working with the RequestDispatcher... you're leaving the ServletContext when you want to call that https resource.
anyway, this is what I thought you tried:
javax.servlet.RequestDispa
rd.forward(request, response);
this is what i suggested:
don't use the ServletContext not the RequestDispatcher...
just use response.sendRedirect...
response.sendRedirect("https://www.microsoft.com?" + request.getQueryString());
i testest my solution on tomcat 4.x and orion successfully.
which server are you using. the error you're getting is quite strange...
so either i dont understand your problem, or you did not try my solution and mixed it up with some ServletContext and RequestDispatcher action...
cheers
Comment from objects 12/11/2002 02:19AM PST
> but I also want my requestobject to be passed to
> Myservlet..
don't think u can do it if you want to switch to https.
the browser needs to resend the request.
Perhaps you could store the relevant parts of the request in the session, or add then to the request url.
> but I also want my requestobject to be passed to
> Myservlet..
don't think u can do it if you want to switch to https.
the browser needs to resend the request.
Perhaps you could store the relevant parts of the request in the session, or add then to the request url.
ASKER
Squuezeme
I tried ur code..Its workiing fine..
Will close the question a little later
I tried ur code..Its workiing fine..
Will close the question a little later
ASKER
Objects,
I couldnt try using request dispatcher because it is giving an error in my websphere.
I have seen the jsdk jar in the lib dir of websphere.
It doestnt have any RequestDispatcher class in it..
(Websphere 3.5)
I couldnt try using request dispatcher because it is giving an error in my websphere.
I have seen the jsdk jar in the lib dir of websphere.
It doestnt have any RequestDispatcher class in it..
(Websphere 3.5)
> I couldnt try using request dispatcher
For the second time, I never mentioned anything about RequestDispatcher.
What I suggested was exactly what Squeezeme said, though I suggested first :-)
Comment from objects 12/11/2002 02:19AM PST
> but I also want my requestobject to be passed to
> Myservlet..
don't think u can do it if you want to switch to https.
the browser needs to resend the request.
Perhaps you could store the relevant parts of the request in the session, or add then to the request url.
For the second time, I never mentioned anything about RequestDispatcher.
What I suggested was exactly what Squeezeme said, though I suggested first :-)
Comment from objects 12/11/2002 02:19AM PST
> but I also want my requestobject to be passed to
> Myservlet..
don't think u can do it if you want to switch to https.
the browser needs to resend the request.
Perhaps you could store the relevant parts of the request in the session, or add then to the request url.
ASKER
would like to give 50 ppints each to squuezeme and objects.
how to do that???
how to do that???
prasad2000
You asked to split points between objects and squuezme.
I have reduced the points on this question from 100 to 50 as indicated by your request at Community Support. Please copy the URL and create a new question in this topic area for the other Experts to whom you wish to award points. The title of the question should read "Points for", followed by the Expert's name. In the question itself, you should paste the link to the original question and perhaps a comment stating that the points are for their help with that question. Once you have created the new questions, you can go back to the original, and accept the comment from the Expert for whom you did not create a new question. The Experts will comment in your new "Points for" question(s), which you then accept and grade to close.
If you have any questions, please don't hesitate to ask.
Thank you.
** Mindphaser - Community Support Moderator **
You asked to split points between objects and squuezme.
I have reduced the points on this question from 100 to 50 as indicated by your request at Community Support. Please copy the URL and create a new question in this topic area for the other Experts to whom you wish to award points. The title of the question should read "Points for", followed by the Expert's name. In the question itself, you should paste the link to the original question and perhaps a comment stating that the points are for their help with that question. Once you have created the new questions, you can go back to the original, and accept the comment from the Expert for whom you did not create a new question. The Experts will comment in your new "Points for" question(s), which you then accept and grade to close.
If you have any questions, please don't hesitate to ask.
Thank you.
** Mindphaser - Community Support Moderator **
{
javax.servlet.http.HttpSes
javax.servlet.ServletConte
javax.servlet.RequestDispa
rd.forward(request, response);
}