質問

I'm using RESTlet to handle PUT requests from a browser and after a successful PUT, I want to redirect the browser to different web page.

Seems like a standard PUT->REDIRECT->GET to me, but I'm not figuring out how to do it in my RESTlet resource.

Here is my code after the PUT has done the requested work:

getResponse().redirectSeeOther("/account");

However that results in the browser getting:

Response Headers
Location    riap://application/account

Of course, "riap" protocol is meaningless to the browser and "application" is not a server name. It seems like there ought to be a way to send a redirect back to the browser without building the entire URL in my redirectSeeOther() call. Building the URL seems like to could be error prone.

Is there an easy way to redirect without building the whole URL from the ground up?

Thanks!

Sincerely,

Stephen McCants

役に立ちましたか?

解決

Although I am not 100% sure in what type of class you are trying to do this.

Try :

Reference reference = getRequest().getRootRef().clone().addSegment("account");
redirectSeeOther(reference);

I usually also then set the body as

return new ReferenceList(Arrays.asList(reference)).getTextRepresentation();

but that may not be necessary for all clients, or at all. I will usually use this style in a class that extends ServerResource - Restlet (2.0.x or 2.1.x).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top