0

Question 1

Here's my project folder,

folder tree

How can I call images folder from UploadContoller?

I already tried with

request.getServletContext().getRealPath("/images");

But it didn't work.


Question 2

project tree

How can I call images > a1.jpg from view > a..jsp?

I already tried with

<img src="/images/a1.jpg">

But it didn't work

SECOND PART

The problem is ok only when i strore my project like (C:\myproject). The problem is When is save my project in other location like (D:\NewFolder\myproject).

Way 1

request.getServletContext().getRealPath("");

--> C:\SpringToolSuite\sts-bundle\pivotal-tc-server-developer-3.2.2.RELEASE\base-instance\wtpwebapps\myproject\

Way 2

request.getContextPath() + "/images/";

-->/myproject/images/

Why i cannot file my project real location. Right Now, my project is under

C:\Users\Star\Downloads\myproject

starly
  • 25
  • 1
  • 7

1 Answers1

1
request.getContextPath()

the above line will give you the context path of your project which is also known as the root of your file tree. Navigate from there.

Answer 1

request.getContextPath() + "/images";

Answer 2

<img src="<%= request.getContextPath()%>/images/a1.jpg">
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80