Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

To get the path from DB on JSP by UseBean  RSS feed

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
   
  I try to insert the image on JSP-page from file, by getting from database the quote on relative path.

  The value in database   <img src = "${pageContext.request.contextPath}/Images/EGEsoon.jpg">

  In JSP I use the useBean:



   Entity


 
  But, instead of expected image in JSP, the  quote is posted on JSP.


Quote_on_Image.png
[Thumbnail for Quote_on_Image.png]
 
Marshal
Posts: 67226
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:

  • Using <c:out> will always HTML-escape the output. That's why you see the markup rather than having it interpreted. This is for safety to prevent script injection attacks. If you are (absolutely) sure that the text is safe¹ you can just use the EL notation without the <c:out> or turn it off with escapeXML="false"
  • If you are expecting to see an image on the page, you need to use an <img> tag, not an input tag. What is it you are really trying to do?


  • ¹ "Safe" means that you are 100% sure that you know what the text will contain. This is never, ever, true of anything that came from the user, 3rd parties, or anywhere other than your own code. Use with caution.
     
    Andrey Dmitriev
    Ranch Hand
    Posts: 42
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Bear Bibeault, thank you for advise, concerning of Img-tage using.    
       I changed code as follows


       And getting value from DB have been changed



       But without success...

       

       
    Wrong_img.png
    [Thumbnail for Wrong_img.png]
     
    Bear Bibeault
    Marshal
    Posts: 67226
    170
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The broken image icon means that the image could not be found. The URL you are using indicates that there is a folder named "Images" (by the way, it's not a good practice to use mixed case for folder names) which contains the EGEsoon.jpg image file. The Images folder is expected to be in the same folder as WEB-INF (note, not in WEB-INF).

    Is this the case? If not, where is the Images folder in relation to there WEB-INF folder?
     
    Andrey Dmitriev
    Ranch Hand
    Posts: 42
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
      That's the thing, that the Images folder is in the same folder as WEB-INF.

       And when I put this script on jsp


        the image inserted on jsp-page successfully!

      But if I use

    when "newsdata.urlimage" represents "${pageContext.request.contextPath}/Images/EGEsoon.jpg" from base

      the mistake is occurred...
     
    Bear Bibeault
    Marshal
    Posts: 67226
    170
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ah. The EL expression inside the string is not going to be evaluated. It's just a string. When you create the string use the actual context path, not the EL expression.

    You can get the context path from the Request instance.
     
    Andrey Dmitriev
    Ranch Hand
    Posts: 42
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Bear Bibeault, gracias!!!

       I use the following tag


       and update the value in base as follows
      'Images/EGEsoon.jpg'

       
      Now the code works successfully!

      It is better for me to study EL more deeper, I suppous.



     
    Fry_Fright.png
    [Thumbnail for Fry_Fright.png]
     
    Bear Bibeault
    Marshal
    Posts: 67226
    170
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Well done!
     
    Bear Bibeault
    Marshal
    Posts: 67226
    170
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Understanding both the EL and the JSTL well is really important to writing smart and effective Java web apps.
     
    All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
    RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
    https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!