I\'m trying to create a web user interface for a Java application. The user interface is going to be very simple, consisting of a single page with a form for users to pose t
EDIT: So far, I've decided on the following:
form.jsp
<form action="/servlet/EngineServlet" method="GET">
<input type="text" name="text" />
</form>
EngineServlet.java
public class EngineServlet extends HttpServlet {
private Engine engine = new Engine();
// does this make sure engine only gets instantiated one time in the entire lifespan of the web application; from what I've read from the servlet lifecycle, it seems like it, but I'd like to hear opinions
public void doGet(HttpServletRequest request,
HttpServletResponse response) {
String text = request.getParameter("text");
ResultBean result = engine.run(text);
request.setAttribute("result", result);
RequestDispatcher dispatcher = request.getRequestDispatcher("result.jsp");
dispatcher.forward(request, response);
// what's the difference between forward, and request.sendRedirect() ?
}
}
result.jsp
<div>The result was: ${result.text}</div>
What do you think of this solution? Any problems that may not be obvious to someone coming from a J2SE background ? I also wrote some doubts that I have in the code as comments. Thanks.