我有一个servlet作为jsp,在xml中声明,我想在Java Config上进行迁移。 网络的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配置:
@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);
}
}
但是,它不起作用。
答案 0 :(得分:0)
您也可以使用@Webservlet
注释 -
@WebServlet(
urlPatterns = {"/url/one", "url/two"}
)
public class ImageUploadServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
........
........
........
}
}