spring-servlet(Spring)をURL "/"でマッピングすると、すべてのリクエストがSpring-servletにリダイレクトされます。.css&.jsなども含まれます。
あなたは解決策を見つけますが、私はあなたに私が使用した別の選択肢を提供しています。
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>static</servlet-name>
<servlet-class>StaticServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>static</servlet-name>
<url-pattern>/images/*</url-pattern>
<url-pattern>/css/*</url-pattern>
<url-pattern>/img/*</url-pattern>
<url-pattern>/js/*</url-pattern>
<url-pattern>/swf/*</url-pattern>
</servlet-mapping>
リソースを提供する静的サーブレット
import java.io.FileInputStream;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
public class StaticServlet extends HttpServlet {
private static final long serialVersionUID = 8458501870440200891L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String resourcePath = req.getServletPath() + req.getPathInfo();
String realPath = getServletContext().getRealPath(resourcePath);
FileInputStream fileInputStream = new FileInputStream(realPath);
try {
IOUtils.copy(fileInputStream, resp.getOutputStream());
} finally {
fileInputStream.close();
}
}
}