Solved

getContentType is returning null

Posted on 2003-10-28
6
1,490 Views
Last Modified: 2008-03-03
Hi,
 I am calling a servlet from a JSP.
WHen I try to check the content type from the request paramente, I get null returned.
How can I set it to "multipart/form-data""

My JSP which is calling the servlet has enctype="multipart/form-data"

Can somebody let me know what I am doing wrong here.

Thanks
Arschie
0
Comment
Question by:aarschie
  • 3
6 Comments
 
LVL 14

Accepted Solution

by:
kennethxu earned 500 total points
ID: 9636388
make sure that you are using post as form action. it works for me as always:

try out this jsp page:
<%=request.getContentType()%><p>
<form method=post enctype="multipart/form-data">
<input type=text>
<input type=submit>
</form>

you should see null first, but after you submit, you should see something like:
multipart/form-data; boundary=---------------------------7d335d1cbb0446

Servlet will be the same result.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9636394
post your code if you still have problem.
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 9640427
it returnl null, because your ServletContainer don't know how to parse multipart/form-data
so, you need a good library to work with it. Try to use jakarta commons/fileupload - it's perfect.
you can find it on:

 http://jakarta.apache.org/commons/fileupload/index.html
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9643537
>> it returnl null, because your ServletContainer don't know how to parse multipart/form-data
Content type is sent from browser as http header entry, servlet container should not change it by contract. so it's not the issue of whether container knows how to handle a certain content type or not. my sample code clearly shows that container does pass down the content type.

>> Try to use jakarta commons/fileupload - it's perfect.
Yes, this will help to get the form data and uploaded file. another good one is jspsmartupload from www.jspsmart.com
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
We need a new way to communicate time sensitive or critical info.   The best part of my role at xMatters is visiting our clients all over the world to learn about how they operate their businesses, share insights that xMatters has gleaned across…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now