I am using Aspose Java Cells.GridWeb 8.6.1 and I am having trouble figuring out how the GridWebBean works.
I based my code off the examples provided on github.
The first API call to my servlet works as expected where I call gridweb.getHTMLBody() and write its output to the response’s writer.
On all subsequent calls, gridweb.getHTMLBody() is writing to the output stream and closing it before I finish the doPost method and I cannot figure out why.
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response) {
GridWebBean gridweb = page.getBean(request);
gridweb.setReqRes(request, response);
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
response.setCharacterEncoding("UTF-8");
path = request.getServletContext().getRealPath("/");
webPath = request.getServletContext().getContextPath();
try {
gridweb.prepareRender();
final String result = String.valueOf(this.process(gridweb, request, response));
final String html = gridweb.getHTMLBody();
out = response.getWriter();
OBJECT_MAPPER.writeValue(out, new Data(html, result));
out.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
out.close();
}
}
public Object process(GridWebBean gridweb, HttpServletRequest request, HttpServletResponse response) {
String action = request.getParameter("flag");
if (action == null) {
return null;
}
Class clz = this.getClass();
Method method = null;
try {
method = clz.getDeclaredMethod(action, GridWebBean.class, HttpServletRequest.class, HttpServletResponse
.class);
return method.invoke(this, gridweb, request, response);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static final class Data {
private final String content;
private final String result;
private Data(String content, String result) {
this.content = content;
this.result = result;
}
public String getContent() {
return content;
}
public String getResult() {
return result;
}
}