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.
Related
I need to warmup a jetty application. I would like to send requests to my handler class but I want not able to find easy way to create http request/response objects (in request I need only a few attributes like uri, query params, body). Is there any utility class to build them (don't want to have mocks in production code).
Thanks.
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.
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.
My back-end server is built using the Microsoft WCF REST Starter Kit Preview 2. I want to add some request processing to all requests, except for those methods I explicitly disable by marking them with an attribute. I have over a hundred service methods and there are only a few I want to exclude from this extra processing. I'll tag them all if I have to, but I'm trying to avoid disrupting what's already written.
I haven't seen anything I can add to WebInvoke, and adding an interceptor won't let me examine the method that the request is routed to.
I am asking for an explanation of how to register HttpOperationHandler object(s) so I can do my extra request processing (i.e. authorization based on information in the request headers) before it is handed off to the method it was routed to. Can someone please explain how to do this, without rewriting my existing codebase to use Web API?
You can't use an HttpOperationHandler with WCF REST Starter Kit. However the Web API is very compatible with ServiceContracts that were created for WCF REST Starter kit. You should be able to re-host them in a Web API host relatively easily. You may have to change places where you access WebOperationContext, but it should not be a huge change.
I solved my problem by adopting another method. It authenticates all requests. I can't control which method it applies to, but I was able to work around that.
I created a custom ServiceAuthorizationManager class to process the Authorization header. The CheckAccess() method returns true to allow the request through or false if the user is not authenticated or not authorized to perform the service. I hooked it up to the ServiceHost for my services by creating a custom WebServiceHostFactory class and assigning an instance to the Authorization.ServiceAuthorizationManager in its CreateServiceHost() methods.
Although I can't directly check method attributes for the service being executed, the Message.Headers member of the object passed to CheckAccess() has a To property that contains the URI of the service being called. If necessary, I could examine it to determine what method the request would be routed to.
The ServiceAuthorizationManager applies to all requests, so no web methods or classes must be marked with any special attributes to enable it.
I have a web cam that can send an image via HTTP PUT to a web server. I'd like to process this in ASP.NET MVC, but it doesn't natively support PUT. Is there any way to trick it into treating the request as a POST? I'm looking to get the Request.Form and Request.Files properties populated.
ASP.NET MVC supports PUT requests by putting the HttpPut attribute on the action.
(In earlier versions you might need to use the AcceptVerbs attribute...)
Are you sure it doesn't support HTTP Put? I see that it is listed within the HttpVerbs Enumeration: http://msdn.microsoft.com/en-us/library/system.web.mvc.httpverbs.aspx
All you should have to do is ensure that you have decorated your action appropriately.
This does not appear to be possible. I've just used the Request.InputStream to read in a bitmap directly.