Error in JSP include

8

I have the following situation:

Servlet instantiated at root

/ MinhaServlet

Jsp instantiated in a folder inside the root:

  

/folder/file.jsp

Within this file I have the following

<img src="_img/editar.png">
<a href="_global/topoErro.jsp">Editar</a>
<jsp:include page="_global/topoErro.jsp" /> </div>

Note that both the image and the href link are pointing to folders that are in the root of the application but should be with ../ before this file is in / folder as well as / _img and / _global.

My question is why does jsp include give error when using the same way as href if the files that are in href and the file that is in jsp include are the same?

_global,
_img

They are folders that are in the root! And my Servlet is also annotated in root

@WebServlet(
            name="MinhaServlet", 
            urlPatterns={"/MinhaServlet"}
           )

No web.xml message

In my project it looks like this: Here I am having trouble sticking. erro404.jsp

<jsp:useBean id="constantes" class="util.Constantes" />     
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>    
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="_global/_css/estiloSite.css" />
<title>${constantes.tituloSite}</title>
</head>
<body class="fadeIn">

 <div id="topo"> <jsp:include page="../_global/topoErro.jsp" /> </div>
 <div id="meio"> <jsp:include page="erro404Conteudo.jsp" /> </div>
 <div id="mapa"> <jsp:include page="../_global/mapaErro.jsp" /> </div>
 <div id="creditos"> <jsp:include page="../_global/creditosErro.jsp" /> </div>

 </body>
</html>

error404Content

<div id="central">

        Esta página não existe! <br/>
        Código do Erro : ${statusCode} <br/>
        <img src="_img/editar.png">
        <a href="_global/topoErro.jsp">Editar</a>
        <jsp:include page="_global/topoErro.jsp" />

</div>
    
asked by anonymous 13.08.2015 / 14:22

2 answers

1

Use jstl:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<a href="<c:url value="/jsp/index.htm"/>">TEST</a>
    
20.10.2015 / 21:54
1

I think it's best to use absolute paths ...

<img src="/SuaAplicação/_img/editar.png">

<a href="/SuaAplicação/_global/topoErro.jsp">Editar</a>

<jsp:include page="/_global/topoErro.jsp" /> </div>

If you do not want to use absolute path to the page's HTML links, just use:

<img src="../_img/editar.png">

<a href="../_global/topoErro.jsp">Editar</a>

But, do not include: jsp use the path starting only with '/'.

Note: If you do not explicitly declare your app name for absolute paths, you can use $ {pageContext.request.contextPath} in your JSP. =)

    
07.06.2017 / 16:58