Thanks Fernando, I was looking for some code like this!
Fernando Wermus-2 wrote: > > Hi, > > Instead using a servlet you could try the following (you can find the > whole > code at wicketstuff pickwick ) > > This way you will have the session because your are into the > requestCycle.... > > On your WicketApp.... > > mount(new URIRequestTargetUrlCodingStrategy("/upload") { > @Override public IRequestTarget decode(RequestParameters > requestParameters) { > try { > return new > UploadRequestTarget(decodeParameters(requestParameters).getString("uri")); > } catch (Exception e) { > throw new WicketRuntimeException(e); > } > } > }); > > Your own class for uploading images or whatever you want.... > > public class UploadRequestTarget implements IRequestTarget { > String parameters; > > public UploadRequestTarget(String parameters) { > this.parameters=uri; > } > > public void detach(RequestCycle requestCycle) {} > > public void respond(RequestCycle requestCycle) { > HttpServletRequest > request=((WebRequest)requestCycle.getRequest()).getHttpServletRequest(); > HttpServletResponse > response=((WebResponse)requestCycle.getResponse()).getHttpServletResponse(); > > response.setHeader("Connection","close"); > > FileItemFactory factory = new DiskFileItemFactory(); > ServletFileUpload upload = new ServletFileUpload(factory); > > List items=null; > PrintWriter out=null; > try { > out = response.getWriter(); > items = upload.parseRequest(request); > > for (int i = 0; i < items.size(); i++) { > DiskFileItem item = (DiskFileItem) items.get(i); > // As we are interested not in regular form fields, we > filter only files > if (!item.isFormField()) { > String fileName=COMPLETE IT > item.write(new File(fileName)); > out.print("RESP.100"); > out.flush(); > } > } > } catch (FileUploadException e1) { > out.print("RESP.200"); > // flush the stream to speed up applet notification > out.flush(); > e1.printStackTrace(); > } catch (Exception e) { > e.printStackTrace(); > } > > } > > > On Sun, Jul 19, 2009 at 3:20 PM, Altuğ B. Altıntaş <alt...@gmail.com> > wrote: > >> Hi Igor; >> >> I found the problem; problem is when i hit my UploadServlet via http-get >> method , i simply write the url and hit the enter then below code is >> working >> >> Session wicketSession = Session.get(); >> >> I can get wicket Session, wow !! it is great... >> >> BUT ... >> >> When i hit my UploadServlet via http-post method, swfupload access in >> that >> way then i can NOT access wicketSession. >> >> I mean this code : >> >> Session wicketSession = Session.get(); >> >> it throws : >> >> java.lang.IllegalStateException: you can only locate or create sessions >> in >> the context of a request cycle >> >> Any idea ? >> >> Thanks >> >> Altug.. >> >> >> 2009/7/14 Igor Vaynberg <igor.vaynb...@gmail.com> >> >> > that doesnt make any sense. all things within the webapp share the >> > session. you guys are welcome to create a quickstart that replicates >> > this. >> > >> > -igor >> > >> > On Tue, Jul 14, 2009 at 3:47 AM, Altuğ B. Altıntaş<alt...@gmail.com> >> > wrote: >> > > Also I have a problem like yours. >> > > >> > > Servlet session and Wicket's session are different so you are getting >> > nul. >> > > Just debug your application and you will see that they have different >> > > session Id's. >> > > >> > > I tried to use WicketSessionFilter but it doesn't work. >> > > >> > > I am using wicket 1.3.5. >> > > >> > > Cheers... >> > > >> > > Altug. >> > > >> > > 2009/6/23 danisevsky <danisev...@gmail.com> >> > > >> > >> hello, I am using MyMultiFileUploadServlet for uploading files and >> in >> > some >> > >> wicket component I need find out how many files was uploaded. >> > >> I was trying to set this number to the HttpSession in >> > >> MyMultiFileUploadServlet and get it in the component: >> > >> >> > >> HttpSession httpSession = ((WebRequest) >> > >> getRequest()).getHttpServletRequest() >> > >> .getSession(); >> > >> String count = httpSession >> > >> .getAttribute("filesCount"); >> > >> >> > >> but count is always null. Is there any way how to get some data from >> > >> servlet? Thanks >> > >> >> > > >> > > >> > > >> > > -- >> > > Altuğ. >> > > >> > >> > --------------------------------------------------------------------- >> > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> > For additional commands, e-mail: users-h...@wicket.apache.org >> > >> > >> >> >> -- >> Altuğ. >> > > > > -- > Fernando Wermus. > > www.linkedin.com/in/fernandowermus > > -- View this message in context: http://www.nabble.com/how-to-get-some-data-from-servlet-tp24166796p24695219.html Sent from the Wicket - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org