On-line advisor for contact-lenses: Java Web
Application with WEKA
1. Start a new project: File -> new project -> WEB ->
Dynamic WEB project. Call the project Lab6.
2. Grab file contact-lenses.arff and put it into C:\web\Lab6\WebContent. Link this input file to
your project by choosing add - new - file -advanced. This is our training
dataset for classification.
3. Add new file index.html to
WebContent (R-click on WebContent folder). All html and jsp files have
to be created under the WebContent
folder. Index.htm is the first screen which is sent to the user when he
requests your application. Here we put links to different application parts.
4.
It is time to connect WEKA libraries. R-click on project folder: properties. In
tab Libraries select: add external jars. Select weka.jar from your weka installation directory. Right-click on weka.jar in the
Project explorer and select Build->add to build path
5.
Also add weka.jar to the folder: WEB-INF - lib by choosing New file and linking
it to the existing weka.jar file in your weka directory. In order to make web
application reference weka.jar, export
project as a .war file once. Export into directory
C:\apache-tomcat-7.0.8\webapps. This is how you can deliver your application,
after the development is complete.
6.
Create new jsp file inputform.jsp.
Here user will enter parameters of a person who needs contact lenses. Note that
form has action ClassifyServlet and method "post". This means that
when user clicks Classify button on this form, method doPost of servlet ClassifyServlet will be called. Servlet
"ClassifyServlet" is yet to be written. Also note that select elements on the form
are not hard-coded but generated by java code from the input dataset.
7.
Restart tomcat. Test that inputform.jsp works properly, either by typing http://localhost/Lab6 in browser, or by R-click on the code
window - run on server. This will open tab where the jsp page will be
displayed. Do not press classify button, because we did not add the handling servlet class yet.
8.
In Java Resources - src folder create a new package "servlets", add new class file ClassifyServlet.java to this
package. Note that this servlet does do much: it only
redirects the request from the inputform.jsp to another java server page.
9.
Add new jsp file J48OutputPage.jsp
to the WebContent folder. This is where the
classification model is built, then the new record is classified (defined in
the inputform.jsp by the user), and the output is written to this output page.
To demonstrate the capabilities of posting user choices, this page contains:
indexes of selected options from HTML SELECT tag in the inputform,
and the print of a new record, where the last attribute is the predicted class.