当你在jsp页面通过JS方式调用restful web services服务提供的某个方法时,往往需要在方法中获取request,response等对象,例如,假如你希望在方法中判断用户输入的验证码与你保存到session中的值是否一致,那么你就必须要获取request对象。那jersey是如何满足这一需求的呢?很简单,只要通过@Context标注就可以实现,具体就是在你需要调用的方法中增加一如@Context HttpServletRequest request的参数,调用的时候不用传入这个参数,直接在方法中直接调用request对象即可。
下面是一个检验验证码的例子
pojo类的方法如下:
@GET
@Produces(MediaType.TEXT_PLAIN)
public String validate(@DefaultValue("") @QueryParam("authCode") String authCode,
@Context HttpServletRequest request){
String flag = "false";
String sessionAuthCode = ""+request.getSession().getAttribute("authCode");
if(sessionAuthCode != null && sessionAuthCode.equalsIgnoreCase(authCode)){
flag = "true";
}
return flag;
}
页面通过jquery进行访问:
jQuery.ajax({
type: "GET",
url: '<%=path%>/services/authCodeValidator',
data: "authCode="+authCode,
success: function(data) {
flag = data;
if(flag == "false"){
alert("验证码错误!");
return;
}
}
});
分享到:
相关推荐
RESTful Web Services 中文版 高清 PDF 电子书
RESTful Java Web Services, Master core REST concepts and create RESTful web services in Java, Jose Sandoval, Copyright 2009 Packt Publishing
如Amazon的简单存储服务与Atom发布协议等 ·探讨各种流行编程语言的Web services客户端 ·展示如何用三种流行框架实现RESTful services —— Ruby on Rails、Restlet(基于Java)和Django(基于Python) ·关注实际...
RESTful Java Web Services (2009).pdf This book is for developers who want to code RESTful web services using the Java technology stack together with any of the frameworks Jersey's JAX-RS, Restlet's ...
RESTful Web Services 中文版,详细教程
Building RESTful Web Services with Spring 5 – Second Edition: Leverage the power of Spring 5.0, Java SE 9, and Spring Boot 2.0 Find out how to implement the REST architecture to build resilient ...
Java Restful Web 源代码Java Restful Web 源代码Java Restful Web 源代码Java Restful Web 源代码Java Restful Web 源代码Java Restful Web 源代码Java Restful Web 源代码Java Restful Web 源代码Java Restful Web...
NULL 博文链接:https://coolzhi.iteye.com/blog/588543
RESTful Web Services Cookbook 中文版,Web开发人员必备良药
RESTful Web Services 英文版 RESTful Web Services渐渐开始流行,大量用于解决异构系统间的...很多网站和应用提供的API,都是基于RESTful风格的Web Services,比较著名的包括Twitter、Google以及项目管理工具Redmine。
Django RESTful Web Services 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
讲解REST与面向资源的架构(ROA)的概念与原理,如何编写符合REST风格的Web 2.0应用。仅用学习使用,不可用于商业用途,如有版权问题,请联系删除!
Java RESTful Web Service实战.pdf Java RESTful Web Service实战.pdf
Building RESTful Web Services with Go:Initially, SOAP-based web services became more popular with XML. Then, since 2012,REST picked up the pace and gulped SOAP in whole. The rise of a new generation ...
RESTful WebServices中文版.pdf 总共47M,我最多一次只能上传30M,不得不吧他压缩成两部分,这个是第一部分,第二部分下载地址:...下载完成后把文件名改成:RESTful WebServices中文版.part1.rar
Building RESTful Web Services with Java EE 8 is a comprehensive guide that will show you how to develop state-of-the-art RESTful web services with the latest Java EE 8 APIs. You will begin with an ...
Table of Contents ...Chapter 9 Scaling RESTful Services (Performance of Web Services) Chapter 10 Building a Web Client (Consuming Web Services) Chapter 11 Introduction to microservices
Building RESTful Web services with Go 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
RESTful webservices – Client API in Java - Jersey