Reputation: 103
Presently I am running the application from eclipse and have uploaded an image file in the location and I am passing this as a request attribute to the JSP user page.
Issue (or) questions
Thank you.
xml context
<context-param>
<param-name> tempfile.dir </param-name>
<param-value> tmp_files </param-value>
</context-param>
File Location
F:\Techie\Servers_Apache\apache-tomcat-7.0.55\tmp_files\user_profile_pic.jpg
servlet
request.setAttribute("user_profile_pic", uploadedImagePath);
HTML tag in home.jsp
<img src= "${user_profile_pic}" alt="Mountain View" style="width:304px;height:228px">
.
Upvotes: 2
Views: 1026
Reputation: 38
1) First of all upload/write the file to some location in server, which is publicly accessible, like ROOT or some folder inside ROOT.
2) As you wrote "But when I am trying to access the file using the below File URL, Image not render?", because it is a file URL, but browser only understands http URLs so it should be http URL, like http://localhost:8080/tmp_files/user_profile_pic.jpg
etc.
3) You can make a properties or constants file in your code, and make variable like URL and PATH, to set http URL and file upload path respectively. In this way, you can set/change the values before deploying the war in tomcat within the Linux Server.
Upvotes: 1