Solved

getContentType is returning null

Posted on 2003-10-28
6
1,569 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apache server configuration 7 92
java.util.concurrent.locks in java 3 204
ejb on wildfly 5 46
junit example issue 2 25
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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