当前位置: 软件>java软件
为Servlet添加支持REST式URL ServletREST
来源: http://www.oschina.net/p/servletrest
发布时间:2015-01-14
本文导语: 为Servlet添加支持REST式URL: 不改变习惯,仅仅在servlet内部完成doGet, doPost,doDelete,doPut等方法即可映射到较为复杂的REST URL eg: /book/head first java/对应的URL表达式为:/book/*//book/head first java/chapter/1对应的URL表达式为:/book/*/chapter/* 您所要...
为Servlet添加支持REST式URL: 不改变习惯,仅仅在servlet内部完成doGet, doPost,doDelete,doPut等方法即可映射到较为复杂的REST URL
eg:
/book/head first java/
对应的URL表达式为:
/book/*/
/book/head first java/chapter/1
对应的URL表达式为:
/book/*/chapter/*
您所要做的: 仅仅需要在web.xml中配置一个filter 仅仅需要在集成HttpServlet添加一个注解(eg:@RestSupport("/book/*/chapter/*"))
下面附加一个使用示范:
@RestSupport("/book/*/chapter/*")
public class ChapterServlet extends HttpServlet {
private static final long serialVersionUID = -1534235656L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// code here ...
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// code here ...
}
protected void doPut(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// code here ...
}
protected void doDelete(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// code here ...
}
}
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。