0

In my jsp page in tag (img src="upload/<%=a.getUrlimmagine()%>") i have this error

Bad value in "upload/ " for attribute "src" on element "img":DOUBLE_WHITE SPACE in PATH

How can I solve it?

Albzi
  • 15,431
  • 6
  • 46
  • 63
Alex
  • 2,075
  • 5
  • 27
  • 39

2 Answers2

0

You would need to use the replaceAll method for String:

<img src="upload/<%=a.getUrlimmagine().replaceAll(" ", "%20")%>" />
developerwjk
  • 8,619
  • 2
  • 17
  • 33
0

Because URLs should not have spaces (see : Are URLs allowed to have a space in them? ) you should encode your url so the unsafe characters will be replaced with some strings representing them (i.e. space becoming %20)

So you either do this in the getUrlimmagine() in your bean or do the encoding in the jsp page.

If you are sure that the only unsafe charcter in your image names is spaces so you can use String.replace() in the backing bean or use the JSTL replace function h in your jsp page

otherwise if you want the cleanest solution, you should definitely read this article : What every web developer must know about URL encoding by Stéphane Épardaud

A cleaner solution to get the same result without using JSP expression is in this answer by BalusC

Community
  • 1
  • 1
Rami
  • 328
  • 1
  • 13
  • The problem is "upload/<%=a.getUrlimmagine()%>" is seen as "upload/ ".Namely <%=a.getUrlimmagine()%> is for html a white space – Alex Feb 25 '14 at 10:16
  • When in debug ,what is the value returned by `getUrlimmagine()` ? you can also check this answer http://stackoverflow.com/a/18085207/696299 it's more clean that using JSP expression – Rami Feb 25 '14 at 14:10