Code of upload
[CODE]
package com.webphotogallery.server;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.FileCleanerCleanup;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FileCleaningTracker;
public class UploadPhoto extends HttpServlet{
/*
*
*/
private static final long serialVersionUID = 144332L;
public void service(HttpServletRequest request,HttpServletResponse
response)
throws ServletException, IOException {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
String UPLOAD_DIRECTORY =
"./src/com/webphotogallery/public/wpgimg/album/";
//String UPLOAD_DIRECTORY = "wpgimg/album/";
List<FileItem> items = null;
try {
items = upload.parseRequest(request);
}
catch (FileUploadException e) {
e.printStackTrace();
}
Iterator iter = items.iterator();
while(iter.hasNext())
{
FileItem it = (FileItem)iter.next();
if(it.isFormField())
UPLOAD_DIRECTORY+=it.getString() + "/";
else
{
File uploadedFile = new
File(UPLOAD_DIRECTORY + it.getName());
try{
it.write(uploadedFile);
}catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
[/CODE]
Code of servlet wich return String[] of images
[CODE]
package com.webphotogallery.server;
import java.io.File;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.webphotogallery.client.LoadPhotoFromAlbum;
public class LoadPhotoFromAlbumImpl extends RemoteServiceServlet
implements LoadPhotoFromAlbum{
/**
*
*/
private static final long serialVersionUID = 403L;
public String[] getImageName(String category) {
File photo = new
File("src/com/webphotogallery/public/wpgimg/album/"
+ category);
//File photo = new File("wpgimg/album/" + category);
String[] photoList = photo.list();
return photoList;
}
}
[/CODE]
Daniele.
2009/1/14, gregor <[email protected]>:
>
> Perhaps you are building a data structure to hold a map of image names
> for the different albums that is done once and once only in one of
> your servlets? That would explain why when you add a new image it does
> not appear on your album lists until you restart the server.
>
> If you post the code for your file upload servlet (the one that
> uploads a new image) and your RPC servlet that returns lists of image
> names for a given album, we might be able to help you sort it out
>
> regards
> gregor
>
> On Jan 14, 8:56 am, mon3y <[email protected]> wrote:
>> Hmmm..i just read that and it confused me
>>
>> What i meant to say is. Every time you send a photo to your servlet
>> add a timestamp
>>
>> myPhoto + System.getCurrentTime() + . jpg;
>>
>> Then your are going to have to keep and array of timestamps for each
>> photo. So when you load the photos you know which timestamp belongs to
>> which photo.
>>
>> Just an idea.
>>
>> HTH
>> :)
>>
>> On Jan 14, 2:02 am, Daniele B <[email protected]> wrote:
>>
>> > I've a problem with my photogallery application.
>> > Application work like this:
>> > On textbox enter a album name.
>> > On FileUpload widget, select image to upload on server.
>> > When user click on album widget, program send a GWT-RPC call to a
>> > servlet which send back string array of images URL.
>> > But when I upload a new photo, it's not viewed...only when I restart
>> > application new photo are view.
>>
>> > Sorry for my english.
>>
>> > Daniele.
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---