spring mvc annotation - 我无法将url映射到控制器,请帮帮我

时间:2013-04-29 14:56:57

标签: spring spring-mvc annotations url-routing

我有.jsp页面:index.jsp,其形式为link:

<form name="firstForm" method="get" action="list.form">
 //-//-//

         <a href = "removeFromStorage?id=<%=index %>">Remove from storage</a>
 //-//-//

</form> 

我有我的控制器:

@Controller

@RequestMapping(value = "/removeFromStorage")

public class MyController {

@RequestMapping(value = "/removeFromStorage", method = RequestMethod.GET)
public String test(@RequestParam("name") String name, ModelMap model){

    //must get index of order, that must delete
    //int index_remove = new Integer(req.getParameter("index"));


    return "index";//request.getRequestDispatcher("hello.jsp").forward(req,res);
}

}

如何将控制器(MyController)映射到url(removeFromStorage)?

我在MyController的注释中写了什么来处理来自.jsp-page的url = removeFromStorage?

1 个答案:

答案 0 :(得分:0)

您拥有的控制器映射

@RequestMapping(value = "/removeFromStorage", method = RequestMethod.GET)value = "/removeFromStorage"

声明对路径/removeFromStorage的GET http请求的处理,该路径相对于应用程序的上下文。要使锚<a href>相对于上下文路径指向removeFromStorage,您可以将其更改为:

<a href = "${pageContext.request.contextPath}/removeFromStorage?id=<%=index %>">Remove from storage</a>