Why request.getRequestDispatcher doesn't work? - http

I have a main JSP and process JSP. In process jsp I am committing the response and forward the response to a success page.
request.getRequestDispatcher("success.jsp").forward(request, response);
I am able to commit the response at the server side. Process jsp is also able to forward the response to success JSP.
But the url shows for example: http://process.jsp?param1=value1&parm2=value2
I want my output to display a clean as in url http://success.jsp
Please Note: This works perfectly fine for Java Servlet, i just tried it.
I am using only JSP instead of Java servelet, since this is our project requirement.
Can anyone suggest me a solution for this?

RequestDispatcher#forward() Is supposed to forward both the request and the response objects to another resource within the server. No response goes back to the client when you do a forward() and this is why the client shows the same initial URL.
For the client to show another URL you could use HttpServletResponse#sendRedirect(). This does go back to the client making it do a new request to the URL you want. So change it to:
response.sendRedirect("success.jsp").
Remember not to commit the response before doing this or you'll get an IllegalStateException
As to why you say that on a Servlet works, I'm not sure why, but is not how forward() is supposed to work, and JSP are compiled to Servlets so in the end they should behave the same.

Related

Does 'RedirectToAction' Calls the controller's constructor again?

I'm using ASP.NET MVC Core to build a practice project. I've noticed that inside my controller if the current method returns a redirect, such as RedirectToAction("SomeAction"), the controller gets constructed again before moving to the 'SomeAction' action.
Does that mean that RedirectToAction is actually performing a new HTTP Request and not just reusing the same request for 'SomeAction'?
That is correct. According to MSDN:
Returns an HTTP 302 response to the browser, which causes the browser
to make a GET request to the specified action.
So it is effectively returning control all the way to the browser, which then issues a new request to the server. You can use a tool like Fiddler to test this out and see the behavior.

Response Redirect URL returns HTTP Error 400 - Bad Request

I'm a noob when it comes to ASP.NET. I know few basic commands such as Response.Redirect("URL") to redirect my application web page to a different location.
However i receive HTTP Error 400 - Bad Request, whenever i try to use the code shown below
Response.Redirect(Server.UrlEncode(this.Downloadlink));
where this.Downloadlink is a user defined property which returns something like this
http://mdn.vatsag.net/fp;files/DOWNLOAD/VTSetup.exe
If i post this link in the browser, the .exe file pops up (means the link is good)
However this error comes when i use the ASP.NET code.
Any form of response on this issue/reason is deeply appreciated.
See here: http://www.kirit.com/Response.Redirect%20and%20encoded%20URIs
In short: if you quickly want to fix the issue, remove the part of your code that is UrlEncoding the URL!

NodeJS Express DynamicView Helper with an http request

I hava a node.js app running on express with a dynamicViewHelper that hits an http service with http.request. Unfortunately, when I try to do this, because the http request is asynchronous and the function calling it is not, the page just renders before the http request is finished and I end up with undefined on my page.
I am basically looking for a way to put an asynchronous action (the http request), inside of a dynamic view helper which gets rendered out on the page. I know I can't just turn it into a synchronous function, so I am looking for another way to get that dynamic data to the view.
Also, is there a way to cache the data that is returned from an http.request()? I don't want to put it on the session, but I want any further requests made to the exact same URL to possibly be cached... Not as big of a deal as the first part of my question, though.
I figured it out. I'll just load it in my route so that res.render() isn't called until the request is done.

How to know if the current Servlet request is the result of a redirect?

Is there a way to know if the request has been redirected or forwarded in the doGet method of a Servlet?
In my application, when a user (whose session has timed out) clicks on a file download link, they're shown the login page, which is good. When they login, they are immediately sent the file they requested, without updating the page they see, which is bad. Basically, they get stuck on the login screen (a refresh is required).
What I want to do is interrupt this and simply redirect to the page with the link, when a file is requested as a result of a redirect.
Perhaps there are better ways to solve this?
The redirect happens client-side. The browser is instructed by the previous request to send a new request, so to the server it does not make a difference. The Referer header might contain some useful information, but it's not certain.
When redirecting you can append some parameter, like ?targetPage=dowloadpage and then check if the parameter exists. You may have to put this in a hidden field on the login page if you want it to be transferred through multiple pages.
If you're using container managed authentication, then I don't believe you can detect this since the server will only involve your resource once authentication has been completed successfully.
If you're managing authentication differently, please explain.

Weblogic server: Why response sent prior to post completion

When analyzing traffic with a packet sniffer, we are seeing an http response from a weblogic server prior to the completion of the http post to that server.
In this case, the jsp page on the server is basically a static page, no logic to do anything with the contents of the post at this time.
But why would the server send the response prior to completion of the post?
I found Weblogic documentation about how to configure the server to ignore a denial-of-service attack using Http post. Maybe that is what is happening?
No one I know has seen this behaviour before. Maybe some weblogic-savvy person will know what is going on.
Thanks
I don't think that Weblogic is analyzing the JSP to determine whether it is static or not.
My guess is that either
someone else was accessing the server at the same time
you saw the answer to a previous request
[EDIT] To determine what is going on, I suggest to set a breakpoint in the JSP. If you still get an answer without hitting the breakpoint, something further up the stack must be intercepting the request (for example, a cache).

Resources