You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rashmi Rubdi <ra...@gmail.com> on 2007/06/03 05:19:36 UTC
Re: Making a directory visible to tomcat
On 5/29/07, Peter Dawn <pe...@gmail.com> wrote:
> guys,
>
> i am using tomcat 5.0. now i have created a file on my server at
> C:\data\packet.xml. when somebody accesses my web app remotely, i want
> the user to type in http://ipaddress:8080/packet.xml to be able to
> access this file.
One way to access the XML file at http://ipaddress:8080/packet.xml is
to write either a Filter or a Servlet, and specify /packet.xml as the
URL mapping for this Filter or Servlet in web.xml
And inside the Filter or Servlet, you would use Java I/O to access a
file that is outside the web application's context (in your case root
context).
For example:
---------------------------------------------------------------------------------
ShowPacketXMLFilter.java
---------------------------------------------------------------------------------
package somepackage;
import javax.servlet.*;
import java.io.*;
public class ShowPacketXMLFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain) throws
IOException, ServletException {
servletResponse.setContentType("application/xhtml+xml");
PrintWriter out = servletResponse.getWriter();
BufferedReader br = new BufferedReader(new
FileReader("C:/data/packet.xml"));
String line;
while ((line = br.readLine()) != null) {
out.println(line);
}
}
public void destroy() {
}
}
--------------------------------------------------------------------------
web.xml
--------------------------------------------------------------------------
<filter>
<filter-name>ShowPacketXMLFilter</filter-name>
<filter-class>somepackage.ShowPacketXMLFilter</filter-class>
<description>
This filter reads packet.xml from disk
and displays it's content at /packet.xml
</description>
</filter>
<filter-mapping>
<filter-name>ShowPacketXMLFilter</filter-name>
<url-pattern>/packet.xml</url-pattern>
</filter-mapping>
> can somebody please tell me how i can make a directory outside the
> installation folder visible to tomcat.
With Java I/O API you will be able to access any file , even if it is
outside the web application's context.
I don't know if there's a way to access any file outside the web app's
context using Servlet API , others may know.
>
> thanks
>
-Rashmi
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org