GWT: How to return plain text from my servlet?

I am using GWT 2.4. I have a form in which I create a submit button so

private Button createSaveButton() { final Button saveButton = new Button("Save"); saveButton.getElement().setAttribute("name", SaveXmlServlet.SAVE_BUTTON_PARAM_NAME); saveButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { formPanel.submit(); } }); return saveButton; } // createSaveButton 

I define an onComplete handler for this form

  formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() { @Override public void onSubmitComplete(SubmitCompleteEvent event) { Window.alert(event.getResults()); } }); 

Servlet I submit a form to return results in plain text.

  res.setContentType("text/plain"); final PrintWriter out = res.getWriter(); out.print(saveSucceeded); out.close(); 

However, when I do make a warning, it will attach the "<pre>" tags to the output. For example, if the servlet displays "true", then what is warned to the user "<pre> true </pre>". How to get this only to output what was written in response? I could do a manipulation string to remove the "<pre>" tags, but it looks like I'm not solving the main problem. Thanks - Dave

+8
gwt
source share
3 answers

I donโ€™t think you can do something about it, but itโ€™s easy to do without weird text manipulations:

 public String getPlainTextResult(SubmitCompleteEvent event) { Element label = DOM.createLabel(); label.setInnerHTML( event.getResults() ); return label.getInnerText(); } 
+8
source share

There is another solution - to set the content type to text/html .

+10
source share
 response.setContentType("text/plain; charset=ISO-8859-2"); 

Try this, right before going out. Hope this helps.

+1
source share

All Articles