0
从一个js页面(角度)我调用一个REST请求,GET方法,我是否会传递一个标题,这是我从REST请求调用的函数:从GET请求中获取运动衫的标题
allstaffworking: function(_getstaff){
var currentToken = _GetToken();
var Headers = {
token: currentToken.stringtoken
};
console.log("idtoken"+Headers);
if (currentToken !== null) {
$http({
method : 'GET',
headers: Headers,
url : REST_URL+'staff/working'
}).then(function successCallback(response) {
_getstaff(response)
}, function errorCallback(response) {
console.log(response.statusText);
});
} else {
console.log("NON SEI LOGGATO!!!");
}
},
内部消除headers: Headers,
它的工作原理,但我想传递一个重要的JSON字符串:{"idtokenStaff":11,"staffType":{"idstaffType":2,"type":"Dipendente"},"tokenStaff":"88d08m8ve4n8i71k796vajkd01"}
的头。我不知道我怎么能在泽西采取这个字符串。这是Java文件中与我有REST方法:@HeaderParam("token") String token
:
@Path("/staff")
public class StaffController {
BaseDao sDao = new StaffDaoImpl();
StaffDao stfDao = new StaffDaoImpl();
TokenStaffDao tsDao = new TokenStaffDaoImpl();
TokenStaff ts = new TokenStaff();
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Staff> getStaff()
{
List<Staff> listOfStaff=sDao.getAll(Staff.class);
return listOfStaff;
}
@GET
@Path("/working")
@Produces(MediaType.APPLICATION_JSON)
@Consumes("application/json")
public List<Staff> getWStaff(@HeaderParam("token") String token) throws JSONException
{
JSONObject jsonObj = new JSONObject(token);
Boolean id = tsDao.getExistence(jsonObj.getInt("idtokenStaff"));
if (id){
List<Staff> listOfWStaff=stfDao.getAllW();
return listOfWStaff;
}
else
return null;
}
}
从以头。我如何获取标题的元素?
你是什么意思*“元首”*? – Andreas
我的json字符串的每一个元素都传递给Header,例如只有“idtokenStaff”的值 –
你问的是如何在JavaScript代码中用JSON字符串构建一个头值,或者你问如何解析' Java中的token参数为JSON,还是你要求其他东西? – Andreas