我有一个用于图像上传的简单servlet,用户选择一个图像,然后servlet完成其工作,然后将其写入 上传 目录。我的项目布局:
project ├───static │ ├───img │ └───js ├───upload └───WEB-INF └───lib
上载图像后,用户将被重定向到其位置:
http://localhost:8080/upload/[image MD5 hash].png
上载代码的效果很好,但是Tomcat在请求url时仍返回404错误,即使图像在那里:
> wget http://localhost:8080/upload/f5d1da2cadf3bd1c1b9196ec522a5d73.png SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc syswgetrc = C:\GnuWin32/etc/wgetrc --2013-01-16 03:45:33-- http://localhost:8080/upload/f5d1da2cadf3bd1c1b9196ec522a5d73.png Resolving localhost... 127.0.0.1, ::1 Connecting to localhost|127.0.0.1|:8080... connected. HTTP request sent, awaiting response... 404 Not Found 2013-01-16 03:45:33 ERROR 404: Not Found. >
update classes and resources在我的IDE Intellij中单击后,它可以工作:
update classes and resources
> wget http://localhost:8080/upload/f5d1da2cadf3bd1c1b9196ec522a5d73.png SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc syswgetrc = C:\GnuWin32/etc/wgetrc --2013-01-16 03:48:11-- http://localhost:8080/upload/f5d1da2cadf3bd1c1b9196ec522a5d73.png Resolving localhost... 127.0.0.1, ::1 Connecting to localhost|127.0.0.1|:8080... connected. HTTP request sent, awaiting response... 200 OK Length: 11666 (11K) [image/png] Saving to: `f5d1da2cadf3bd1c1b9196ec522a5d73.png' 100%[==========================================================>] 11,666 --.-K/s in 0s 2013-01-16 03:48:11 (72.9 MB/s) - `f5d1da2cadf3bd1c1b9196ec522a5d73.png' saved [11666/11666] >
第二件事是,当我手动删除该映像时,我仍然可以下载它(Tomcat是否可以进行某种形式的兑现?):
> del f5d1da2cadf3bd1c1b9196ec522a5d73.png > wget http://localhost:8080/upload/f5d1da2cadf3bd1c1b9196ec522a5d73.png SYSTEM_WGETRC = c:/progra~1/wget/etc/wgetrc syswgetrc = C:\GnuWin32/etc/wgetrc --2013-01-16 04:12:25-- http://localhost:8080/upload/f5d1da2cadf3bd1c1b9196ec522a5d73.png Resolving localhost... 127.0.0.1, ::1 Connecting to localhost|127.0.0.1|:8080... connected. HTTP request sent, awaiting response... 200 OK Length: 11666 (11K) [image/png] Saving to: `f5d1da2cadf3bd1c1b9196ec522a5d73.png' 100%[==========================================================>] 11,666 --.-K/s in 0s 2013-01-16 04:12:25 (93.2 MB/s) - `f5d1da2cadf3bd1c1b9196ec522a5d73.png' saved [11666/11666] >
我的 web.xml 文件:
<servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/static/*</url-pattern> <url-pattern>/upload/*</url-pattern> </servlet-mapping>
有人可以告诉我问题出在哪里吗?
在开发中进行部署时,资源将在开发资源而非工作空间中进行部署,而在工作空间中删除时,必须重新部署开发资源中的更改
用我的英语不好意思,