新上传的文件和Tomcat? [英] New uploaded files and Tomcat?

查看:168
本文介绍了新上传的文件和Tomcat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的servlet用于图像上传,用户选择一个图像,然后servlet完成它的工作,然后把它写到 upload 目录。我的项目布局:

 项目
├───静态
│├───img
│└───js
├───上传
└───WEB-INF
└───lib

上传图片后,用户被重定向到它的位置:

  http:// localhost:8080 / upload / [image MD5 hash] .png 

上传代码工作得很好,但是当请求url时,即使图像在那里,Tomcat也会返回404错误:

 > wget http:// localhost:8080 / upload / f5d1da2cadf3bd1c1b9196ec522a5d73.png 
SYSTEM_WGETRC = c:/ progra〜1 / wget / etc / wgetrc
syswgetrc = C:\GnuWin32 / etc / wgetrc
- 2013年1月16日03:45:33-- http:// localhost:8080 / upload / f5d1da2cadf3bd1c1b9196ec522a5d73.png
正在解析本地主机... 127.0.0.1,:: 1
连接到localhost | 127.0.0.1 |:8080 ...已连接。
HTTP请求发送,等待响应... 404未找到
2013-01-16 03:45:33错误404:未找到。
>

单击更新类和资源我的IDE,Intellij,它的工作原理:

 > wget http:// localhost:8080 / upload / f5d1da2cadf3bd1c1b9196ec522a5d73.png 
SYSTEM_WGETRC = c:/ progra〜1 / wget / etc / wgetrc
syswgetrc = C:\GnuWin32 / etc / wgetrc
- 2013年3月16日03:48:11-- http:// localhost:8080 / upload / f5d1da2cadf3bd1c1b9196ec522a5d73.png
正在解析本地主机... 127.0.0.1,:: 1
连接到localhost | 127.0.0.1 |:8080 ...已连接。
发送的HTTP请求,正在等待响应... 200 OK
Length:11666(11K)[image / png]
保存到:`f5d1da2cadf3bd1c1b9196ec522a5d73.png'

100%[=============================================== ===========>] 11,666 - .- K / s在0s

2013-01-16 03:48:11(72.9 MB / s) - ` f5d1da2cadf3bd1c1b9196ec522a5d73.png'saved [11666/11666]
>

第二件事是当我手动删除这个图片时,我仍然可以下载它一些兑现?):

 > del f5d1da2cadf3bd1c1b9196ec522a5d73.png 
> wget http:// localhost:8080 / upload / f5d1da2cadf3bd1c1b9196ec522a5d73.png
SYSTEM_WGETRC = c:/ progra〜1 / wget / etc / wgetrc
syswgetrc = C:\GnuWin32 / etc / wgetrc
- 2013年1月16日04:12:25-- http:// localhost:8080 / upload / f5d1da2cadf3bd1c1b9196ec522a5d73.png
解析本地主机... 127.0.0.1,:: 1
连接到localhost | 127.0.0.1 |:8080 ...已连接。
发送的HTTP请求,正在等待响应... 200 OK
Length:11666(11K)[image / png]
保存到:`f5d1da2cadf3bd1c1b9196ec522a5d73.png'

100%[=============================================== ===========>] 11,666 - .- K / s在0s

2013-01-16 04:12:25(93.2 MB / s) - ` f5d1da2cadf3bd1c1b9196ec522a5d73.png'saved [11666/11666]
>

我的web.xml文件:

 < servlet-mapping> 
< servlet-name>默认< / servlet-name>
< url-pattern> / static / *< / url-pattern>
< url-pattern> / upload / *< / url-pattern>
< / servlet-mapping>

有人能告诉我问题在哪里吗?


在我的英文里,s

I have a simple servlet for images uploading, a user select an image and the servlet does its job and then write it to upload directory. My project layout:

project
    ├───static
    │   ├───img
    │   └───js
    ├───upload
    └───WEB-INF
        └───lib

After uploading the image, the user is redirected to it's location:

http://localhost:8080/upload/[image MD5 hash].png

The uploading code works pretty well, but Tomcat returns 404 error when requesting the url even when the image is there:

> 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.
> 

After I click update classes and resources in my IDE, Intellij, it works:

> 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]
>

The second thing is that when I manualy delete this image, I still can download it (does Tomcat do some sort of cashing?):

> 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]
> 

My web.xml file:

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/static/*</url-pattern>
    <url-pattern>/upload/*</url-pattern>
</servlet-mapping>

Could someone please tell me where is the problem?

解决方案

when deploy in development your resouce will deploy in development resource not workspace ,and when you remove in workspace must redeploy for change in development resource

sory in my english,

这篇关于新上传的文件和Tomcat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆