0
@At("/notes") @Service
public class NotebookService {

    private Note note =new  Note();

    public NotebookService(){
        ObjectifyService.register(Note.class);
    }

    public Note getNote() {
        return note;
    }

    public void setNote(Note note) {
        this.note = note;
    }

    @Post
    public String postNote(){
        note.setDate(new Date());
        Objectify objectify=ObjectifyService.ofy();
        objectify.save().entities(note).now();
        return "/servlet";
    }
}

It throws java.lang.ClassCastException: java.lang.String cannot be cast to com.google.sitebricks.headless.Reply when I return a url string from a method annotated with @post. return type of the post method is String, then why is it expecting a Reply ?

Note that @Service is required for my yet to be coded get method which will reply JSON.

4

1 回答 1

1

The reason it gives a ClassCastException is that the Sitebricks API will at some point see the @Service -annotation in your class and act accordingly. It will take the returned object (in your case a java.lang.String) and try and cast it to a com.google.sitebricks.headless.Reply

In order to achieve what you want, you should instead return the following:

return Reply.saying().redirect("/servlet");

That is how you do a redirect using the Reply API.

于 2013-06-19T23:43:39.957 回答