【发布时间】:2016-04-18 10:58:17
【问题描述】:
下面是我的路线
public Restlet createInboundRoot(){
Router router = new Router(getContext());
router.attach("account/profile",UserProfile.class);
下面是资源类UserProfile.java
@post
@path("add")
public void addUser(User user){
@post
@path("modify")
public void modifyUser(User user){
@post
public void test(){//only this is called
我想调用一个资源类并为一个资源类执行几个相同的功能。这意味着,我上面的资源类处理与 UserProfiles 相关的功能,例如添加、修改。
网址是:
account/profile/add => 添加用户
account/profile/modify => 修改用户
无论如何,上面我的实现不起作用,因为只能通过 account/profile/ 调用 test() 方法
我也尝试过使用 Pathparams。但它也不起作用。 对于路径参数:
router.attach("account/profile/{action}",UserProfile.class);
已添加并在资源类中,
@post
@path("{action}")
public void addUser(@pathparam("action") String action, User user){
谁能告诉我我的问题出在哪里。
【问题讨论】:
-
你能把你的错误日志贴在这里吗?
-
感谢 karthi 的关注。没有抛出任何错误。服务器只返回 403 作为响应
-
好吧!这意味着您尝试访问的资源存在,但服务器无法给出正确的响应。您可以尝试这些事情,确保您的目录具有所有权限,并使用 @Produces 注释指定生成类型为 json 或 XML,并尝试使用 @put 或 @get 方法。有时帖子是罪魁祸首。
-
谢谢Karthi .. 我尝试使用单个方法注释@POST 和单个ULR 到源,然后它工作。我没有看到任何权限问题。当 2 个 URL 调用此资源时,就会出现此问题。
-
请问有什么想法吗?
标签: java jakarta-ee jax-rs restlet