내 webapp의 일부 파일은 WAR 파일의 간단한 폴더에 있습니다. 요청은 매우 빨랐습니다. 브라우저가 파일을 캐시하자마자 파일이 변경 될 때까지 파일 내용을 다시 요청하지 않았습니다.
이제 파일을 다른 위치에 배치하고 파일을 전달하는 서블릿을 구현했습니다. 코드는 간단하지만 성능이 떨어집니다. 다음은 최소한의 예입니다.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>File</servlet-name>
<servlet-class>test.FileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>File</servlet-name>
<url-pattern>/file/*</url-pattern>
</servlet-mapping>
</web-app>
FileServlet
public class FileServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
FileSystem fs = FileSystems.getDefault();
Path path = fs.getPath("/some/folder/", req.getPathInfo());
Files.copy(path, resp.getOutputStream());
}
}
예를 들어 바람둥이와 같은 성능을 얻을 수 있도록 어떻게 개선 할 수 DefaultServlet
있습니까?
"마지막 수정"헤더가 도움이 될 수 있습니다. 여기에서 "클라이언트의 캐시"섹션을 참조하십시오.
http://www.onjava.com/pub/a/onjava/excerpt/jebp_3/index2.html
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다