Is it possible to use libraries within the structure of the java project?

Asked

Viewed 73 times

2

My question is the following, can I by relative way link my . JSP to a library within the project directory? Or only in the server directory: Webapps, etc?

At the moment, when I want to show an image on my system, I do the following:

<img src="http://localhost:8080/minhaLogo.png" width=30>

Which is in the directory:

C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.5\webapps\ROOT\minhaLogo.png

Everything below webapps/root is easily accessible.

However, I would like to use the logo within a relative path of my project folder structure:

inserir a descrição da imagem aqui

I tried it in many ways, but I didn’t succeed, as much as the console says I had a HTTP GET 200 image does not load. It’s possible to do what I’m trying to do?

I tried something like, with several directory variations, but no success:

<img src="<%= request.getContextPath() + "/newLib/minhaLogo.png" %>" width=30>

Thank you very much.

EDIT:

As it is a test page, it is simply a page with the image in the body:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>teste link relativo</title>
</head>
<body>
    <a class="bt"><img src="<%= request.getContextPath()%>/newLib/minhaLogo.png" width=30></a>
</body>
</html>

1 answer

2

Test with the code below and check if it solves.

<img src="<%= request.getContextPath()%>/newLib/minhaLogo.png" width=30>
  • I’ll test, thank you

  • although the tag is right on F12 <img width="30" src="/Qualiteweb_novo_10-08-18/newLib/myLogo.png"> and return a "HTTP GET 200", the image does not appear

  • 1

    Could send the code of the page you use this image?

  • I edited the question with the code, but since it’s just a test page, there’s not much :/

  • 2

    I tested your code and it works perfectly related to tag img. There is nothing wrong not to show the image on the screen.

  • I thought it had something to do with my company’s network, so I did the same thing on my personal computer and nothing

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.