I want to do this. If someone log with this url http://localhost:8080/ url. he should redirect to login servlet. So I create a code for it as this
@WebServlet(name = "RootController", urlPatterns = {"/"})
public class RootController extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
RequestDispatcher out = request.getRequestDispatcher("/login");
out.forward(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
But when I link the CSS and js files as this
<link href="resources/css/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
those files not linked. But I changed the root servlet urlPatterns
to /abc
it works correctly. Why is that? the path of the resource folder is correct. What should I do to achieve my task?