struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jane Wayne <jane.wayne2...@gmail.com>
Subject how to write json/xml output using struts 2 and rest + convention plugin
Date Thu, 04 Oct 2012 22:21:32 GMT
i've downloaded the demo apps for struts 2 v2.3.5 SNAPSHOT for today.
i am trying to understand and study the rest struts2-rest-showcase
webapp.

in the rest showcase, the OrdersController class has the following method.

public String editNew() {
 model = new Order();
 return "editNew";
}

the user is taken to orders-editNew.jsp. on this page, the form posts
to: action="%{#request.contextPath}/orders". the action to handle this
form is as follows.

public HttpHeaders create() {
 ordersService.save(model);
 addActionMessage("New order created successfully");
 return new DefaultHttpHeaders("success").setLocationId(model.getId());
}

at this point, the user is taken to orders-index.jsp. however, i do
not want to take the user to this page. i instead want to write a
JSON/XML message back saying something (just like the action message)
to indicate success/failure. how do i do this?

i imagine my client application posting data to: /orders/new
and then receiving some JSON message:
{ "results" : "New order created successfully" }

any help is appreciated.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message