Monday, July 20, 2009

Wicket:: how to output text (like a Servlet)

I wanted to output regular text, like a servlet, rather than an HTML - which is Wicket's default. This was to be used by a PingPage, to make sure the service is up and running. This is the way you can do that:

public class PingPage extends WebPage {
public PingPage() {
getRequestCycle().setRequestTarget(new IRequestTarget() {
public void detach(RequestCycle requestCycle) {}
public Object getLock(RequestCycle requestCycle) { return null; }

public void respond(RequestCycle requestCycle) {
WebResponse r = (WebResponse)requestCycle.getResponse();
r.setContentType( "text/plain" );

PrintStream printStream = new PrintStream(r.getOutputStream());
Post a Comment