Estou fazendo uma aplicação web com java e Eclipse no NetBeans
Minha pasta WEB-INF possui uma pasta chamada admin e outra chamada global aonde eu tenho uma pasta chamada '_estilo' e dentro um arquivo chamado estilo.css que contem o estilo do site.
Na pasta admin tenho um arquivo chamado lista.jsp e outro chamado index.jsp
No index.jsp tenho um formulário de cadastro que chamo o servlet.
<jsp:useBean id="listaDeSalas" class="dao.sala.ListaSalas" /> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <c:set var="lista" value="${empty listaDeSalas.getListaSalas()}" /> <div id="indexMeio"> <h2>Cadastro de Professor</h2><br /><br /> <form action="../ProfessorServlet" method="post"> <input type="hidden" name="acao" value="AdicionaProfessor" /> <label>Login</label> : <input type="text" name="login" id="login" maxlength="10" required="required" /><br /><br /> <label>Senha</label> : <input type="text" name="senha" id="senha" maxlength="10" required="required" /><br /><br /> <label>Nome</label> : <input type="text" name="nome" id="nome" maxlength="200" required="required" /><br /><br /> <label>Sala</label> : <select id="sala" name="sala" required="required" > <c:choose> <c:when test="${lista == true}"> <option value="#">Sem sala cadastrada </c:when> <c:otherwise> <option value="#">Escolha a Sala <c:forEach var="salas" items="${listaDeSalas.getListaSalas()}"> <option value="${salas.id}">${salas.nome} </c:forEach> </c:otherwise> </c:choose> </select><br /><br /><br /> <input type="submit" value="Cadastrar"> </form><br /> </div>
O cadastro esta funcionando corretamente.
O problema ocorre após o cadastramento onde eu chamo um redirecionamento para a pagina lista.jsp que irá listar os cadastros.
RequestDispatcher rd = request.getRequestDispatcher("admin/listar.jsp"); rd.forward(request, response);
Bom, se eu chamo direto a pagina listar.jsp que tem o apontamento a um arquivo css.
<link type="text/css" rel="stylesheet" href="../_global/_css/estiloSite.css" />
da forma baixo:
http://localhost:8080/imwsaogotardo/admin/listar.jsp
O arquivo de estilo carrega corretamente.
Mas se, após o servlet gravar o cadastro, ele mesmo fizer o redirecionamento,
RequestDispatcher rd = request.getRequestDispatcher("admin/listar.jsp"); rd.forward(request, response);
embora o redirecionamento saia corretamente, isto é, a página abre normalmente, mas o arquivo de estilo, não carrega.
Mas, se eu altero o endereço do arquivo de estilo no listar.jsp
<link type="text/css" rel="stylesheet" href="_global/_css/estiloSite.css" />
ocorre o contrário; se eu chamar direto
http://localhost:8080/imwsaogotardo/admin/listar.jsp
O estilo não carrega. Mas se passa pelo sevlet, ai carrega
Como resolver isso?
Meu xml esta assim:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>imwsaogotardo</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>ProfessorServlet</servlet-name> <servlet-class>imwsaogotardo.src.controller.ProfessorServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>ProfessorServlet</servlet-name> <url-pattern>/imwsaogotardo/ProfessorServlet</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> </session-config> <jsp-config> <taglib> <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri> <taglib-location>/WEB-INF/fmt.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri> <taglib-location>/WEB-INF/fmt-rt.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jstl/core</taglib-uri> <taglib-location>/WEB-INF/c.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri> <taglib-location>/WEB-INF/c-rt.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri> <taglib-location>/WEB-INF/sql.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri> <taglib-location>/WEB-INF/sql-rt.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jstl/x</taglib-uri> <taglib-location>/WEB-INF/x.tld</taglib-location> </taglib> <taglib> <taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri> <taglib-location>/WEB-INF/x-rt.tld</taglib-location> </taglib> </jsp-config> </web-app>