icemico
asked on
sendRedirect not working
I have this page that handles the uploading of files from the client to the application server. I used the jakarta file-upload library. What I did is I submitted the form to a servlet which handles the uploading. My problem is that I need to forward the user to a jsp page after a successful or unsuccessful upload. I used the response.sendRedirect() to send the user from the servlet to the jsp. the problem is that it redirects to a blank page.
One more thing is that we used jsp:include with the attribute flushtrue. I don't know if this is the reason why it doesn't redirects (although it does redirects when I run the application locally).
Is there any workaround on this?
One more thing is that we used jsp:include with the attribute flushtrue. I don't know if this is the reason why it doesn't redirects (although it does redirects when I run the application locally).
Is there any workaround on this?
try requstDispatcher.forward() instead of redirect
ASKER
I've already tried requestDispatcher.forward( ) but it generates more bugs (ex: css not applied) and most times it cannot locate the .jsp file.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
request.dispatcher is working but still the CSS is not applied. What does it mean that the css is not relative to the relativepath?
how do u refer css in your jsp file?
like this <link rel="stylesheet" href="../../somecss.css"" type="text/css">
OR
like this <link rel="stylesheet" href="<html:rewrite page="/somecss.css" />" type="text/css"> [With Struts]
I asked u, do u use struts?
like this <link rel="stylesheet" href="../../somecss.css"" type="text/css">
OR
like this <link rel="stylesheet" href="<html:rewrite page="/somecss.css" />" type="text/css"> [With Struts]
I asked u, do u use struts?
ASKER
I'm not using struts. Its the first option on how I refer css in my jspfile.
Ok. make use of request.getContextPath here like follows
<link rel=stylesheet type="text/css" href="<%= request.getContextPath() %>/style.css">
keep in mind that the request.getContextPath() will give u the instance context path. For ex. if your webapp is called as
http://localhost:8080/myapps
myapps is the context path. You then have to provide the additional path to the css.
<link rel=stylesheet type="text/css" href="<%= request.getContextPath() %>/style.css">
keep in mind that the request.getContextPath() will give u the instance context path. For ex. if your webapp is called as
http://localhost:8080/myapps
myapps is the context path. You then have to provide the additional path to the css.
ASKER
Thanks fargo. but i have problems regarding the path.
Let's say my url is something like this: http://localhost:8080/main/sub/main.jsp
When I upload a document (submit the form) I send the form to a servlet. (mapped in the web.xml). so the url becomes: http://localhost:8080/main/upload
from the uploadservlet, I forward the user back to the main.jsp by using the following lines:
String returnSave = "/sub/main.jsp?action=save ";
request.RequestDispatcher( request.ge tContextPa th()+retur nSave).for ward(reque st, response);
When I deploy it to my server I get this error when it's time to redirect back to the main.jsp: The requested resource (/main/sub/main.jsp) is not available.
Any idea why this happen?
other info: I'm using Jboss as my appserver
Let's say my url is something like this: http://localhost:8080/main/sub/main.jsp
When I upload a document (submit the form) I send the form to a servlet. (mapped in the web.xml). so the url becomes: http://localhost:8080/main/upload
from the uploadservlet, I forward the user back to the main.jsp by using the following lines:
String returnSave = "/sub/main.jsp?action=save
request.RequestDispatcher(
When I deploy it to my server I get this error when it's time to redirect back to the main.jsp: The requested resource (/main/sub/main.jsp) is not available.
Any idea why this happen?
other info: I'm using Jboss as my appserver
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It worked! Thanks to both of you guys! It's now working smoothly locally. I just hope it will be the same when I upload it to our app server.
Thanks again!
Thanks again!
glad to be of help..:-)