Java Reference
In-Depth Information
The wizard will serve a basic servlet skeleton that needs to be completed with a min-
imal set of code lines:
@WebServlet("/test")
public class TestServlet extends HttpServlet
{
protected void doGet(HttpServletRequest
request, HttpServletResponse response) throws
ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello World JBoss AS 7");
out.close();
}
protected void doPost(HttpServletRequest
request, HttpServletResponse response) throws
ServletException, IOException {
}
}
Note
Notice that this small class bears the @WebServlet annotation, which has been
introduced by the Servlet 3.0 API, and it allows registering a servlet without us-
ing the web.xml configuration file. In our example, we have used it to customize
the servlet URL binding to use "/test" , which would otherwise be defaulted by
Eclipse to the class name.
We will complete the application with a JBoss file descriptor named jboss-
web.xml ; although this not mandatory, it can be used to redefine the context root:
<jboss-web>
<context-root>/hello</context-root>
</jboss-web>
Search WWH ::




Custom Search