This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mithil Shukla
Greenhorn
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

Struts.xml

<struts>
<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-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>

<global-results>
<result name="login" type="tiles">login</result>
<result name="home" type="tiles">home</result>
</global-results>
<action name="searchMaterialData" class="org.deloitte.pemex.action.SearchMaterialAction" method="getMaterialData">
<result type="json"/>
</action>

</package>


Action Class: SearchMaterialAction.java

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)) {
schemaId=8;
}

//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.

Regards,
Mithil.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic