3

i was trying to follow this example http://www.codejava.net/coding/upload-files-to-database-servlet-jsp-mysql to insert images into a blob field of a db.

I have problems on the line

Part filePart = request.getPart("photo");

I get these errors:

- Part cannot be resolved to a type
- The method getPart(String) is undefined for the type HttpServletRequest

I was trying to figure out what jar i should include but i didnt find nothing working good.

If i use ctrl+shift+o on clipse it gives me two possibile packages:

import com.sun.java.swing.plaf.windows.TMSchema.Part;
com.sun.xml.internal.ws.wsdl.writer.document.Part;

But no one of them seems to contain what i need

If i try to import javax.servlet.http.Part i get this error

The import javax.servlet.http.Part cannot be resolved

I still miss something.

I installed TOMCAT 7, i imported javax.servlet.http.Part and now i have no error from eclipse. Thanks everybody

MDP
  • 4,177
  • 21
  • 63
  • 119

4 Answers4

4

You need the Java EE jar with the following import:

import javax.servlet.http.Part;
Cem Sultan
  • 354
  • 2
  • 12
3

Looking at the code on that page, I'd wager a guess that it's...

import javax.servlet.http.Part;
jama
  • 325
  • 1
  • 6
  • You need to add the servlet JAR to your class path. That info can be found at: http://stackoverflow.com/questions/4119448/the-import-javax-servlet-cant-be-resolved – jama Oct 14 '13 at 14:39
3
import javax.servlet.http.Part;
2

This depends to a large degree on the Servlet Container you are using. The tutorial mentions, that it uses Servlet API 3.0. If you are using Tomcat 6.0 for example it only supports up to 2.5 which does not seem to have the feature you are trying to use. Tomcat 7 on the other hand supports 3.0.

You could probably hack your servlet container by replacing the servlet-api.jar file with a newer version, but I would recommend upgrading.

ced-b
  • 3,957
  • 1
  • 27
  • 39