I'm trying to understand Spring MVC annotations. I've looked at various tutorials, and I just want to make sure I understand. In this example,
#RequestMapping("/welcome")
am I correct in understanding that welcome is the page making the request to the controller, and not the page the controller sends the response to?
If I understand your phrasing correctly, you are right. The #RequestMapping annotation specifies a URL for which the controller will be invoked to generate page content. #RequestMapping("/welcome") means that when a browser requests http://yoursite.com/welcome this controller will be invoked. The annotation does not specify the name of the view you use to render the page output, so you're free to make the controller construct its response using home.jsp or index.jsp or any other page you want; you do not need to have a view named "welcome." I'm not sure it really makes sense to say that the controller "sends the response to a page," though, because in HTTP the response to a request is a page; the basic idea of a controller is that given a request, it generates a web page to send back to the client as a response.
Related
I have just started with Spring Web Flow. I have a basic doubt. In case of Spring MVC, the #RequestMapping contains the URL mapping, say for eg, #RequestMapping("/home"), this means, when the URL nodeContent is /home, the Contorller with #RequestMapping("/home") will be delegated by the dispatcher servlet. In case of Spring Web Flow, how is this mapping done? I mean, how do we even identify the request URL? is it the flow-location id in flow-registry? Basically, I want to know how to identify that when a Spring web flow is invoked based on what kind of URL request? eq- "https://stackoverflow.com/questions/ask", if this URL has to invoke a flow, how is the mapping done with the URL /ask.
Please can anyone answer this?
The main thinks is, there are two beans which is complete the mapping.
First of all,
FlowHandlerMapping : in general, DispatcherServlet know the request mapping by handler mapping, but in WebFlow, FlowHandlerMapping helps DispathcerServlet to know the mapping. Basically it's "flow-registry". When hit the url, then it's get the url with the id. now it's ready to execute the flow.
FlowHandlerAdapter : When the executable flow url is ready then it's try to load the flow file with id like
configure-flow.xml
Once you successfully get the path then flow will start. The flow will continue until view-state to end-state.
Maintain the order of your view page, because next flow will come in order.
If you have any question, leave in comment section.
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.
I want to submit a form using AJAX to a MVC 3 Controller.
The form and the controller are on two different domains, which is why i want to use CORS.
I have read that the following code should do the trick in ASP.NET:
Response.AppendHeader("Access-Control-Allow-Origin", "*");
from http://enable-cors.org/#how-asp.net
Should this code go directly in the controller that takes the form data?
As far as i know, there has to be some exchange of data between the client posting data and the server, to determine wether CORS is enabled/supported or not, so i figure that the one line of code has to go somewhere else?
Thanks
This could go in the controller. Actually I would probably externalize it in a custom action filter to avoid repeating it in every controller action that needs to be invoked from a cross domain AJAX call. There are no additional steps necessary. Just make sure that your browser supports CORS because if it doesn't adding this line will have strictly no effect whatsoever.
How do I pass parameters from ServletOne to ServletTwo using a HTTP POST through URL intead of using HTTP GET in the servlet?
For example: http://localhost/ServletOne?username=test
If the above link is accessed, in ServletTwo, username test will be displayed.
You've a problem in your class design. The ServletTwo has apparently some code which needs to be reused in ServletOne. You need to refactor that code into a separate Java class. Once done that, all you need to do is to just import/use that Java class in both servlet classes the usual Java way.
I'd like to respond to an HTTP POST in an ASP.Net page.
I've found loads of example of sending an WebRequest, and I can successfully pick that up and read it in my Page_Load.
However, I'd like to then put some data back in the Response, but I can't find any examples of how to do this.
The actual requirement is for an external site to POST to a page and receive back a GUID for their records.
Any help very gratefully received.
It sounds like you should be using an HttpHandler and not a Page.
You create an HttpHandler by implementing the IHttpHandler interface. When implementing the IHttpHandler interface, you have full control over the response in the ProcessRequest method.
Typically ASP.NET page will put its rendered markup (html generated by controls present on it) in response. Going by your requirement, I would suggest you to use generic HTTP handler (.ashx file) that will give you complete control over your response.
See this article for quickstart with ashx: http://www.brainbell.com/tutorials/ASP/Generic_Handlers_(ASHX_Files).html