Mercurial > hg > human-echolocation-java-webapp
diff webapp/WEB-INF/src/HumanEchoServlet.java @ 0:b6acfffd25cd
Initial commit of code. Not in a working state yet. This code is based on the JavaEndToEnd example described on Mathwork's MATLAB Application Deplyment (Web Example Guide for R2013b) - see this project's documentation for more details.
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Wed, 27 Nov 2013 11:10:43 +0000 |
parents | |
children | 76f809129f98 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/webapp/WEB-INF/src/HumanEchoServlet.java Wed Nov 27 11:10:43 2013 +0000 @@ -0,0 +1,76 @@ +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletException; +import javax.servlet.ServletConfig; +import java.io.IOException; +import uk.ac.soton.isvr.*; + +import com.mathworks.toolbox.javabuilder.MWJavaObjectRef; +import com.mathworks.toolbox.javabuilder.MWNumericArray; +import com.mathworks.toolbox.javabuilder.MWException; + +public class HumanEchoServlet extends HttpServlet { + private HumanEcho echo; + + public void init(ServletConfig config) throws ServletException { + super.init(config); + + try { + echo = new HumanEcho(); + } + catch(MWException e) { + e.printStackTrace(); + } + } + + public void destroy() { + super.destroy(); + + if(echo!=null) { + echo.dispose(); + } + } + + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // Test parameter + MWNumericArray test = new MWNumericArray(Integer.parseInt(request.getParameter("test"))); + + double[][] square = new double[0][]; + + // double[][] square = new double[0][]; + // WebFigure figure = null; + + try { + // refers to the mcode function gen_echo.m + Object[] result = echo.gen_echo(1, test); + + MWNumericArray array = (MWNumericArray)result[0]; + square = (double[][])array.toArray(); + + } + catch(MWException e) { + e.printStackTrace(); + } + + StringBuffer buffer = new StringBuffer(); + + buffer.append("<BR>"); + buffer.append("<BR>"); + + buffer.append("<TABLE >"); + for (double[] row : square) + { + buffer.append("<TR>"); + for (double value : row) + { + buffer.append("<TH>"); + buffer.append(new Double(value).intValue()); + } + } + buffer.append("</TABLE>"); + buffer.append("<BR>"); + response.getOutputStream().print(buffer.toString()); + } +}