You mention portlets in your question. Working with Spring and portlets is slightly different than servlets.
So, suppose you have such a portlet
@Controller @RequestMapping("VIEW") // VIEW mapping (as opposed to EDIT) public class MyPortlet { @RenderMapping public ModelAndView handleRenderView(RenderRequest request, RenderResponse response) { ResourceURL resourceUrl = response.createResourceURL(); resourceUrl.setResourceID("myResource"); // this is the id used to reference a @ResourceMapping ModelAndView ret = new ModelAndView("myPortlet"); ret.addObject("resourceUrl", resourceUrl.toString()); return ret; } @ResourceMapping("myResource") public void handleMyResource(ResourceRequest request, ResourceResponse response) { OutputStream out = response.getPortletOutputStream(); // write whatever to output } }
As you can see, @ResourceMapping is identified by a resource identifier. A resource mapping URL can be created using standard API methods and the createResourceURL() and javax.portlet.ResourceURL .
If you prefer to use the taglibrary of the portlet, you can also create a resource URL using the <portlet:resourceRequest> .
Your opinion may look something like this.
myPortlet.jsp
... <script> $.ajax({ url :${resourceUrl}, cache: false, data:$('#myForm').formSerialize(), dataType: "json", type: "GET", contentType: "application/json; charset=utf-8", success: function(jsondata){ ......... ......... ......... } }); </script> ...
pap
source share