简体   繁体   中英

How I load css and js of Bootstrap in a web java application (jsp)?

If I use the controller (Servlet) don't see the Boostrap styles. The events are:

[1] Load login.jsp

[2] Send login information to SessionController (Servlet) throught POST.

[3] SessionController save the information in the Session, create an attribute in the session for indicate to FormsController his work:

request.getSession().setAttribute("user", request.getParameter("usuario"));
request.getSession().setAttribute("pass", request.getParameter("clave"));
request.getSession().setAttribute("pg", "showAll");
request.getRequestDispatcher("FormsController").forward(request, response);`

In this moment pg = "showAll" and SessionController call to FormsController.

[4] FormsController search information in the DataBase and redirect to formularios/datos.jsp

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    switch (request.getParameter("p")) {
      case "new":
        request.getRequestDispatcher("formularios/nuevoformulario.jsp").forward(request, response);
        break;
      case "showAll":
        DBFormulario f = new DBFormulario(request.getSession().getAttribute("user").toString(), request.getSession().getAttribute("pass").toString());
            try {
                request.getSession().setAttribute("formularios", f.consultarFormularios());
                request.getRequestDispatcher("formularios/datos.jsp").forward(request, response);
            } catch (DBExceptionsManager ex) {
                Logger.getLogger(FormsController.class.getName()).log(Level.SEVERE, null, ex);
            }
        break;
    }
}

More information:

index.jsp:

<meta http-equiv="refresh" content="0;URL=login/login.jsp" />

login.jsp: http://s2.subirimagenes.com/imagen/9582471login.png

datos.jsp: http://s2.subirimagenes.com/imagen/9582472datos.png

Views: http://s2.subirimagenes.com/imagen/previo/thump_9582470sin-ttulo.png

The better way to load the resource files I think is to use the tag jstl core library which provides the tag url to proper URL encoding, for using this library you have to import the jstl/core tag library in your jsp and you will get great benefits of the library which contains if-else , for and many more conditions statements.

To import the library, <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> write this in your jsp, and re-write your link tag like below,

<link rel="stylesheet" type="text/css" href="<c:url value='/css/bootstrap.min.css'">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM