| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
12年前发布

为Servlet添加支持REST式URL:ServletREST

为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 ...          }  }

项目主页:http://www.open-open.com/lib/view/home/1350309217367

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1350309217367.html
REST Web框架