Solved

getContentType is returning null

Posted on 2003-10-28
6
1,513 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

15 Experts available now in Live!

Get 1:1 Help Now