Win a copy of Penetration Testing Basics this week in the Security forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.IllegalStateException: getInputStream() has already been called for this request + JSON

Mithil Shukla
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am getting following Error: java.lang.IllegalStateException: getInputStream() has already been called for this request while implementing JSON with Struts2.

Following is the code written


<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />

<package name="default" extends="struts-default,json-default" namespace="/">

<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />

<result name="login" type="tiles">login</result>
<result name="home" type="tiles">home</result>
<action name="searchMaterialData" class="" method="getMaterialData">
<result type="json"/>


Action Class:

public class SearchMaterialAction extends ActionSupport implements ServletRequestAware {

private static final long serialVersionUID = 7596687051484794667L;

private SearchMaterial searchMaterial;
private SearchMaterialDTO searchMaterialDTO;
private List<SearchMaterialDTO> lsearchMaterialDTO;
private List<String> names = new ArrayList<String>() ;
//private Map session;
private HttpServletRequest request;

public String getMaterialData(){

searchMaterial = new SearchMaterial();
System.out.println("Inside class SearchMaterialAction: method: getMaterialData");
int schemaId=7;

Locale locale = request.getLocale();
String userLocaleLanguage = locale.getDisplayLanguage();
System.out.println("The User Language: "+ userLocaleLanguage);

if (null!=userLocaleLanguage && "Spanish".equals(userLocaleLanguage)) {

//System.out.println("Request Object: "+ request.getParameter("materialId"));
System.out.println("materialId: "+ materialId);
System.out.println("materialDesc: "+ materialDesc);
System.out.println("level0: "+ level0);
System.out.println("level1: "+ level1);
System.out.println("level2: "+ level2);
System.out.println("attribute: "+ attribute);
System.out.println("materialType: "+ materialType);
System.out.println("buttonValue: "+ buttonValue);

if ("Search".equals(buttonValue)){
lsearchMaterialDTO = searchMaterial.getMaterial(userLocaleLanguage, schemaId, searchMaterialDTO);
System.out.println("Size of the LIST: "+ lsearchMaterialDTO.get(0).getMaterialID());


return SUCCESS;

Kindly help me with this Error as I am stuck with this issue
I have few question:
I have implemented ServletRequestAware and using the same to get the userLocale. Is it conflicting with the JSONWriter Object.

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic