How can i use Tomcat to serve image files from a public folder outside webapps? I dont want to use a 2nd Apache fileserver on a different port since the image files are part of the same app. And i dont want to create a symlink to the public folder inside webapps since my app is deployed as a war file....Is there a simpler solution similar to using default servlet for static content inside webapps, for static content outside outside webapps
相关问题
- Tomcat and SSL Client certificate
- Can't configure nginx as a proxy for tomcat wi
- Tomcat 8 how to remove sessionCookieName from URL
- tomcat websocket servlet listening port
- How to configure quartz scheduler with spring-styl
相关文章
- Tomcat的User信息可以存储到数据库中吗?
- tomcat的server.xml支持从Oracle中获取数据吗?
- web项目,Resonse Header发生解析错误,请大牛帮忙看看究竟是哪里的问题?
- Apache+Tomcat+JK实现的集群,如果Apache挂了,是不是整个服务就挂了?
- linux环境部署jpress,创建数据库时提提示连接失败
- Making a two way SSL authentication between apache
- Can't start Tomcat as Windows Service
- How to abort Tomcat startup upon exception in Serv
After none of solutions based on defining XMLs worked for me, I found this answer very helpful. Took about a minute, and a small code change: I modified this line
this.basePath = getServletContext().getRealPath(getInitParameter("basePath"));
into
this.basePath = getInitParameter("basePath");
You could have a redirect servlet. In you web.xml you'd have:
All your images would be in "/images", which would be intercepted by the servlet. It would then read in the relevant file in whatever folder and serve it right back out. For example, say you have a gif in your images folder, c:\Server_Images\smilie.gif. In the web page would be
<img src="http:/example.com/app/images/smilie.gif"...
. In the servlet,HttpServletRequest.getPathInfo()
would yield "/smilie.gif". Which the servlet would find in the folder.