如何使用AJAX调用具有指定URL的Controller的@RequestMapping方法
我对 Spring 和 Portlet 非常陌生。我想使用 jqgrid 来显示一些列表。我试图调用控制器中的一个方法,该方法用 @RequestMapping 注释,但该方法没有被调用
我的控制器有以下方法
@Controller(value = "myController")
public class MyController {
@RequestMapping(value="/myURL",method=RequestMethod.GET)
public @ResponseBody MyDTO initItemSearchGrid(RenderResponse response, RenderRequest request){
MyDTO myDto=new MyDTO();
return myDto;
}
}
我使用 AJAX 的 JSP 代码
var urlink="/myURL"; /* myURL is the exact String written in value Attribute of
resourceMapping in Controller*/
$.ajax({
url :urlink,
cache: false,
data:$('#myForm').formSerialize(),
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function(jsondata){
...
}
});
当上面的 AJAX 代码执行时,我的方法没有被调用。
I'm very new to Spring and Portlet. I want to use jqgrid to show some list. I am trying to call a method in controller which is annoted with the @RequestMapping but the method is not being called
My Controller has following method
@Controller(value = "myController")
public class MyController {
@RequestMapping(value="/myURL",method=RequestMethod.GET)
public @ResponseBody MyDTO initItemSearchGrid(RenderResponse response, RenderRequest request){
MyDTO myDto=new MyDTO();
return myDto;
}
}
My JSP code using AJAX
var urlink="/myURL"; /* myURL is the exact String written in value Attribute of
resourceMapping in Controller*/
$.ajax({
url :urlink,
cache: false,
data:$('#myForm').formSerialize(),
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function(jsondata){
...
}
});
When above AJAX code is executing my method is not called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在问题中提到了 Portlet。使用 Spring 和 portlet 与 servlet 有点不同。
因此,假设您有一个像这样的 portlet
正如您所看到的,@ResourceMapping 由资源 ID 标识。资源映射的 URL 可以使用标准 portlet API 方法和类
createResourceURL()
和javax.portlet.ResourceURL
创建。如果您更喜欢使用 portlet 标记库,您还可以使用
标记生成资源 URL。您的视图可能类似于
myPortlet.jsp
You mention Portlets in your question. Working with Spring and portlets is a bit different from servlets.
So, assuming you have a portlet like this
As you can see, the @ResourceMapping is identified by a resource ID. The url for the resource mapping can be created using the standard portlet API methods and classes
createResourceURL()
andjavax.portlet.ResourceURL
.If you prefer to use the portlet taglibrary instead, you can also generate a resource URL using the
<portlet:resourceRequest>
tag.Your view might look something like this
myPortlet.jsp