File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes java.lang.IllegalStateException: getInputStream() has already been called for this request + JSON Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "java.lang.IllegalStateException: getInputStream() has already been called for this request + JSON " Watch "java.lang.IllegalStateException: getInputStream() has already been called for this request + JSON " New topic
Author

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

Mithil Shukla
Greenhorn

Joined: Oct 03, 2012
Posts: 4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.IllegalStateException: getInputStream() has already been called for this request + JSON