FireGlow
26 May 2009, 8:11 AM
Ups I was in the wrong forum :x
I found an example for an Servlet to handle a FileUpload:
public class ArchetypeUploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ArchetypeService archetypeService;
public ArchetypeUploadServlet() {
super();
}
public void doGet(HttpServletRequest request, HttpServletResponse resp)
throws ServletException {
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
archetypeService = ArchetypeServiceImpl.getInstance();
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
items = upload.parseRequest(req);
Iterator it = items.iterator();
File uploadedFile;
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
GregorianCalendar tempDate = new GregorianCalendar();
uploadedFile = new File("D:/server/temp/"
+ tempDate.getTimeInMillis() + ".adl");
item.write(uploadedFile);
User user = (User) req.getSession().getAttribute(
User.USER_LOGGED_IN);
if (user == null) {
throw new AccessControlException(
"Kein User in der Session gefunden.");
}
System.out.println(user);
System.out.println(user.getLogin());
archetypeService.importArchetype(uploadedFile, user);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}I registered it in my web.xml and modul.xml!
My relevant formcode is this:
this.setAction(GWT.getModuleBaseURL() + "ArchetypeUploadServlet");
this.setEncoding(Encoding.MULTIPART);
this.setMethod(Method.POST);
[...]
public void doUpload()
{
if(this.isValid())
{
// //TODO: Fieldbinding would be better, but doesn't work that easily
// this.archetypeDataModel.setFilePath((String) archetypeFile.getValue());
// Dispatcher.get().dispatch( new EHRflexEvent<ArchetypeDataModel>( EHRflexEventType.ARCHETYPE_IMPORT_SUBMIT, this.archetypeDataModel) );
new MessageDialog(this.getAction());
this.submit();
}
}
It works fine so far!
But I'm wondering how I can react on a successful uploading of the file? I don't have any callback or something! Is there a mechanism to react of a successful submit() ?
I found an example for an Servlet to handle a FileUpload:
public class ArchetypeUploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private ArchetypeService archetypeService;
public ArchetypeUploadServlet() {
super();
}
public void doGet(HttpServletRequest request, HttpServletResponse resp)
throws ServletException {
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
archetypeService = ArchetypeServiceImpl.getInstance();
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
items = upload.parseRequest(req);
Iterator it = items.iterator();
File uploadedFile;
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
GregorianCalendar tempDate = new GregorianCalendar();
uploadedFile = new File("D:/server/temp/"
+ tempDate.getTimeInMillis() + ".adl");
item.write(uploadedFile);
User user = (User) req.getSession().getAttribute(
User.USER_LOGGED_IN);
if (user == null) {
throw new AccessControlException(
"Kein User in der Session gefunden.");
}
System.out.println(user);
System.out.println(user.getLogin());
archetypeService.importArchetype(uploadedFile, user);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}I registered it in my web.xml and modul.xml!
My relevant formcode is this:
this.setAction(GWT.getModuleBaseURL() + "ArchetypeUploadServlet");
this.setEncoding(Encoding.MULTIPART);
this.setMethod(Method.POST);
[...]
public void doUpload()
{
if(this.isValid())
{
// //TODO: Fieldbinding would be better, but doesn't work that easily
// this.archetypeDataModel.setFilePath((String) archetypeFile.getValue());
// Dispatcher.get().dispatch( new EHRflexEvent<ArchetypeDataModel>( EHRflexEventType.ARCHETYPE_IMPORT_SUBMIT, this.archetypeDataModel) );
new MessageDialog(this.getAction());
this.submit();
}
}
It works fine so far!
But I'm wondering how I can react on a successful uploading of the file? I don't have any callback or something! Is there a mechanism to react of a successful submit() ?