Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1709
  • Last Modified:

getContentType is returning null

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
aarschie
Asked:
aarschie
  • 3
1 Solution
 
kennethxuCommented:
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
 
kennethxuCommented:
post your code if you still have problem.
0
 
dualsoulCommented:
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
 
kennethxuCommented:
>> 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now