Mercurial > hg > human-echolocation-java-webapp
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:b6acfffd25cd |
---|---|
1 import javax.servlet.http.HttpServlet; | |
2 import javax.servlet.http.HttpServletRequest; | |
3 import javax.servlet.http.HttpServletResponse; | |
4 import javax.servlet.ServletException; | |
5 import javax.servlet.ServletConfig; | |
6 import java.io.IOException; | |
7 import uk.ac.soton.isvr.*; | |
8 | |
9 import com.mathworks.toolbox.javabuilder.MWJavaObjectRef; | |
10 import com.mathworks.toolbox.javabuilder.MWNumericArray; | |
11 import com.mathworks.toolbox.javabuilder.MWException; | |
12 | |
13 public class HumanEchoServlet extends HttpServlet { | |
14 private HumanEcho echo; | |
15 | |
16 public void init(ServletConfig config) throws ServletException { | |
17 super.init(config); | |
18 | |
19 try { | |
20 echo = new HumanEcho(); | |
21 } | |
22 catch(MWException e) { | |
23 e.printStackTrace(); | |
24 } | |
25 } | |
26 | |
27 public void destroy() { | |
28 super.destroy(); | |
29 | |
30 if(echo!=null) { | |
31 echo.dispose(); | |
32 } | |
33 } | |
34 | |
35 | |
36 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
37 // Test parameter | |
38 MWNumericArray test = new MWNumericArray(Integer.parseInt(request.getParameter("test"))); | |
39 | |
40 double[][] square = new double[0][]; | |
41 | |
42 // double[][] square = new double[0][]; | |
43 // WebFigure figure = null; | |
44 | |
45 try { | |
46 // refers to the mcode function gen_echo.m | |
47 Object[] result = echo.gen_echo(1, test); | |
48 | |
49 MWNumericArray array = (MWNumericArray)result[0]; | |
50 square = (double[][])array.toArray(); | |
51 | |
52 } | |
53 catch(MWException e) { | |
54 e.printStackTrace(); | |
55 } | |
56 | |
57 StringBuffer buffer = new StringBuffer(); | |
58 | |
59 buffer.append("<BR>"); | |
60 buffer.append("<BR>"); | |
61 | |
62 buffer.append("<TABLE >"); | |
63 for (double[] row : square) | |
64 { | |
65 buffer.append("<TR>"); | |
66 for (double value : row) | |
67 { | |
68 buffer.append("<TH>"); | |
69 buffer.append(new Double(value).intValue()); | |
70 } | |
71 } | |
72 buffer.append("</TABLE>"); | |
73 buffer.append("<BR>"); | |
74 response.getOutputStream().print(buffer.toString()); | |
75 } | |
76 } |