i am trying to built a Prediciton-Servlet. But i am not able to load my previous built classifier into the servlet. This is my code:
public class SucessPrediction extends HttpServlet {
private static final long serialVersionUID = 1L;
public SucessPrediction() {
super();
// TODO Auto-generated constructor stub
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Get formula input
...
// Read Classifier and predict Success
ServletContext context = getServletContext();
InputStream resourceContent = context.getResourceAsStream("/WEB-INF/J48.model");
try {
Classifier J48 = (Classifier) weka.core.SerializationHelper.read(resourceContent);
if (klassifizierer != null) {out.println("KLASSIFIZIERER IS LOADED");}
predictionResult = J48.classifyInstance(DATA.firstInstance());
DATA.classAttribute().value((int) ergebnis);
return PredicitonResult;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
The Problem is, that it works when i built a normal JAVA Application. But in my servlet it doesn t work. I think it has something to do with File Paths. I read also this hints: File path to resource in our war/WEB-INF folder? But whatever i do, i can not load my classifier and classify my data.
My System is an Eclipse IDE with a integrated Tomcat7 with OS Ubuntu 14.04
Thanks for your help!