This week's book giveaways are in the Cloud/Virtualization and Go forums.
We're giving away four copies each of Cloud Native Transformation: Practical Patterns for Innovation and The Go Workshop and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native Transformation: Practical Patterns for InnovationE this week in the Cloud/Virtualization forum
or The Go Workshop in the Go forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Getting session attributes from multipart/form-data form

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
I have been doing a web application related on online shopping. It has file uploading capability.In some forms,I used enctype="multipart/form-data" for the forms. I set some session attributes in the jsps,in which I put enctype as multipart/form-data for the forms. If I tried to get the session attributes in servlets, I got null. How can I retrieve session and other types of attributes from jsps?

Can anyone give me the answer?

Best regards,

Ramesh Kanagamuthu
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Report post to moderator
I think you're either confusing terms or misinterpreting the problem you're seeing.

I don't think the problem is with the adding or retrieving of variables to or from session. It's most likely that you're not getting the parameters properly. When you respond to multipart requests in your servlets or JSPs, request.getParameter doesn't work. It will always return null.
To retrive your form parameters, you'll need to check the documentation for the upload libraries that you're using.
 
Ramesh kangamuthu
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Report post to moderator
Thanks Ben,

I understood the problem clearly. In multipart request request.getParameter() does not work,I knew. Also I got those type of parameters after checking FileItem's isFormField() method and

fileItemObject.getName()

fileItemObject.getString() methods. No problem.

My problem is how I can get session attributes set in a jsp,that has multipart/form-data form. I tried for the multipart form and got the session attribute as null. If the request is not multipart, result comes.

If I tried the following

NewsList newsList=(NewsList)request.getSession().getAttribute("newsList");

I got the newsList Object as null. This is not null If I try with non-multipart request.

Best Regards,
Ramesh Kangamuthu
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can you post the code that sets the session variables?
Also describe the flow of your application so we know when each component is executed.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Ramesh,

I am also facing the same issue, have you resolved this? Please share me how to fix this issue.

Regards,
Sridhar
 
Marshal
Posts: 67334
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please start a new topic rather than piggy-backing on this old one. And clearly explain your issue.
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!