Jeromy Evans - Blue Sky Minds wrote:
> 
> 
> Hi Johnson, I think just need to read up a little more on Struts 2 as it 
> seems you're trying to do too much yourself based on Struts1 experiences 
> rather than let the framework do more of the routine work. Ian Roughly's 
> book is a good place to start: 
> http://www.infoq.com/minibooks/starting-struts2
> 
> Anyway, in a previous email you mentioned you know how to open an input 
> stream from the image data in your database:
> 
> InputStream in = rs.getBinaryStream("filedata");   
> 
> 
> The StreamResult requires that an input stream is open and available in 
> a public property in your action.  Here's a section from your new action:
> 
> public class MyAction extends ActionSupport {
> //....
> private InputStream imageStream;
> 
> public String execute() {
>    // read data from the database ...
>    //...
>   imageStream = rs.getBinaryStream("filedata");
>    // ...
>    return SUCCESS;
> }
> 
> /** Return an InputStream for the StreamResult */
> public InputStream getImageStream() {
>    return imageStream;
> }
> 
> That's it. We have an open InputStream in a public property in your 
> action.  You don't do anything other than prepare it for reading.
> 
> Now your struts.xml requires the action and result definition.  The 
> definition below states that when your action returns success, the 
> stream result type (StreamResult) should be used and that the name of 
> the InputStream property is imageStream (ie. getImageStream()).  That 
> ties it back into the code above.
> 
> <action name = "myaction" class="MyAction">
>    <result name="success" type = "stream">
>     image/jpeg
>     imageStream
>     filename="image.jpg"
>     1024
>   </result>
> </action>
> 
> Hope that helps.  After you have that working, you can also experiment 
> with getting the content type and filename from properties in your action.
> Hint:  ${contentType}
> 
> Regards,
>  Jeromy Evans
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
> 
> 
> 

Hi, Jeromy, I used the above method to upload and display the images and
succeed. However, if I want to show many images on one page, such as a table
like this:

user_id_1      user_name_1     user_portrait_1(image)
user_id_2      user_name_2     user_portrait_2(image)
user_id_3      user_name_3     user_portrait_3(image)
user_id_4      user_name_4     user_portrait_4(image)
user_id_5      user_name_5     user_portrait_5(image) 

Is there a way to do it?
I used to use display tag to solve similar table display, but with image
URL, it doesn't work.
-- 
View this message in context: 
http://www.nabble.com/Struts-2-File-upload-to-store-the-filedata-tp14168069p23970105.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to