流分辨率条纹
谁能帮助我使用java框架-stripes? 我尝试使用 stripes:file
上传图像,在服务器上调整大小并返回新的 StreamingResolution
return ("image / jpeg"... 我现在不知道如何使用 StreamingResolution
发送以及如何在 jsp 上的 stripes:file
元素之后加载图像?
非常感谢
Could anyone help me with java Framework - stripes?
I try to upload image with stripes:file
, resize on the server and return with new StreamingResolution
return ("image / jpeg"...
I dont now exactly how to send with StreamingResolution
and how can I load image after stripes:file
element on jsp?
Many Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想在上传后在页面上显示图像,则需要处理一些事情。首先,“POST”必须有某种结果,而该结果可能不会是图像数据。也就是说,让您的操作(您的“事件处理程序”,Stripes 人们称之为)返回 StreamingResolution 并没有真正意义,除非您只是希望用户能够像下载文件一样保存图像。
因此,您的图像上传“POST”可能只涉及转发到结果页面的简单分辨率。在该页面内,您可以放置一个 HTML
标记,该标记将“src”设置为另一个 Stripes 操作。现在该操作将返回图像数据的 StreamingResolution。
要解决的一个问题是在两个 HTML 事务中保存图像数据的位置。为此,我会使用 Stripes“闪光瞄准镜”,因为它非常简单。当然,如果您的服务器代码要将图像存储在数据库中,那么您的图像操作 URL 将只包含某种识别信息。
假设您可以找到图像数据,您的服务器端处理程序所要做的就是创建一个 StreamingResolution 实例,该实例具有
stream()
方法的实现。它需要一个参数(HttpServletResponse)。由此,您可以使用response.getOutputStream() 打开一个输出流,将图像数据复制到其中,然后关闭该流。确实没什么可说的。下面是一个发送简单文件的示例,但对您来说,主要区别在于跟踪图像数据,当然还有不同的 MIME 类型:您还需要调用
setAttachment(false);
在开始写出图像数据之前。此示例用于文件下载,因此就我而言,我希望它成为附件(这是默认设置)。但是,如果您要响应从标记生成的“GET”,您不希望它看起来像附件。
Well if you want to show the image on the page after uploading, there are a couple of things to deal with. First, the "POST" is going to have to have some sort of result, and that result probably won't be the image data. That is, having your action (your "event handler", as Stripes people call them) return a StreamingResolution doesn't really make sense unless you just want the user to be able to save the image like a downloaded file.
Thus, your image upload "POST" might involve just a plain resolution that forwards to a result page. Inside that page, you can put an HTML
<img>
tag that has a "src" set to another Stripes action. Now that action will return the StreamingResolution for your image data.One problem to solve is where to keep the image data across the two HTML transactions. For that, I'd use a Stripes "flash scope" because it's pretty simple. If your server code is going to store the image in a database anyway, of course, your image action URL would simply include some sort of identifying information.
Assuming you can find the image data, all your server-side handler has to do is to create a StreamingResolution instance that has an implementation for the
stream()
method. That takes a single parameter (the HttpServletResponse). From that, you'd open up an output stream withresponse.getOutputStream()
, copy the image data out to that, and then close the stream. There's really not much to it. Here's an example that sends out a simple file, but for you the main difference would be keeping track of the image data and of course a different MIME type:You'd want to also call
setAttachment(false);
before you start writing out the image data. This example is for a file download, so in my case I want it to be an attachment (and that's the default). If you're responding to a "GET" generated from an<img>
tag, however, you don't want it to look like an attachment.