Servlet as JSP Java Config

126 views Asked by At

I have a servlet as jsp which is declared in xml, I want to migrate on Java Config. web-xml:

<servlet>
   <servlet-name>App</servlet-name>
   <jsp-file>/app/App.jsp</jsp-file>
</servlet>

<servlet-mapping>
  <servlet-name>App</servlet-name>
  <url-pattern>/app/App.html</url-pattern>
</servlet-mapping>

Java Config:

@Override
public void onStartup(ServletContext servletContext){
  ...
  servletContext.addServlet("App", new AppServlet()).addMapping("/app/App.html");

}

private class AppServlet extends HttpServlet{
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp){
    req.getRequestDispatcher("/app/App.jsp").forward(req,resp);
 }
}

But, it's not working.

1

There are 1 answers

0
Razib On

You may also try this with @Webservlet annotation -

@WebServlet(
        urlPatterns = {"/url/one", "url/two"}
)
public class ImageUploadServlet extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
       ........
       ........
       ........
    }
}