Solved

getContentType is returning null

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

11 Experts available now in Live!

Get 1:1 Help Now