有没有办法使未被打包在war文件中的文件夹可以通过GET请求访问?可能需要在web.xml文件中进行设置。
alternatedocroot
属性(在Glassfish中)来从war外部提供文件(如图像)。
请参见:http://docs.sun.com/app/docs/doc/820-4496/geqpl?l=en&a=view 例如:此属性可以是sun-web.xml文件中sun-web-app元素的子元素,也可以是domain.xml文件中virtual-server元素的子元素。
<property name="alternatedocroot_1" value="from=/images/* dir=/usr/gifs"/>
public class FileDownloadServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String filename = request.getParameter( "filename" );
InputStream is;
try {
is = FileUtils.openInputStream( new File( filename ) );
byte[] buf = new byte[ 8192 ];
int bytesRead;
while ( ( bytesRead = is.read( buf ) ) != -1 )
os.write( buf, 0, bytesRead );
}
catch( ... ) {
}
finally {
is.close();
os.close();
}
response.setContentType( "application/octet-stream" );
}
}