You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kimberly Begley <ki...@gmail.com> on 2008/02/28 07:07:01 UTC
file upload servlet
Hi - I'm trying to compile come java code to upload a file but am getting
errors - it looks like it can't find the javax.servlet stuff to import and
from what I've read online everyone talks about having the directory in the
classpath but I have also read not to mess with my classpath - I'm trying to
compile it from my catalina_home/webapps/appname/WEB_INF directory - does
anyone have any suggestions? I'm sure it's obvious but I just can't see it.
This is my java file:
FileUploadBean.java
package foo;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FileUploadBean extends HttpServlet {
public void doUpload(HttpServletRequest request) throws
IOException {
PrintWriter pw = new PrintWriter(
new BufferedWriter(new FileWriter("Demo.out")));
ServletInputStream in = request.getInputStream();
int i = in.read();
while (i != -1) {
pw.print((char) i);
i = in.read();
}
pw.close();
}
}
and my jsp page looks like this:
<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%--
ResourceBundle bundle =null;
public void jspInit() {
bundle = ResourceBundle.getBundle("forms");
}
--%>
<jsp:useBean id="TheBean" scope="page" class="foo.FileUploadBean " />
<%
TheBean.doUpload(request);
%>
When run "javac -d . FileUploadBean.java" I get this error:
javac -d . FileUploadBean.java
----------
1. ERROR in FileUploadBean.java (at line 3)
import javax.servlet.*;
^^^^^^^^^^^^^
The import javax.servlet cannot be resolved
----------
2. ERROR in FileUploadBean.java (at line 4)
import javax.servlet.http.*;
^^^^^^^^^^^^^
The import javax.servlet cannot be resolved
----------
3. ERROR in FileUploadBean.java (at line 8)
public void doUpload(HttpServletRequest request) throws
^^^^^^^^^^^^^^^^^^
HttpServletRequest cannot be resolved to a type
----------
4. ERROR in FileUploadBean.java (at line 12)
ServletInputStream in = request.getInputStream();
^^^^^^^^^^^^^^^^^^
ServletInputStream cannot be resolved to a type
----------
4 problems (4 errors)
--
Re: file upload servlet
Posted by Kimberly Begley <ki...@gmail.com>.
ah - ok - thanks for clearing that up.
On Thu, Feb 28, 2008 at 4:59 PM, Bob Hall <rf...@yahoo.com> wrote:
>
> --- 10:07PM Wed 27 Feb 2008 Kimberly Begley
> <ki...@gmail.com> wrote:
>
> > Hi - I'm trying to compile come java code to upload
> > a file but am getting
> > errors - it looks like it can't find the
> > javax.servlet stuff to import and
> > from what I've read online everyone talks about
> > having the directory in the
> > classpath but I have also read not to mess with my
> > classpath - I'm trying to
> > compile it from my
> > catalina_home/webapps/appname/WEB_INF directory -
> > does
> > anyone have any suggestions? I'm sure it's obvious
> > but I just can't see it.
> >
>
> The CLASSPATH warnings are associated with starting
> Tomcat - not compiling your java code; servlet-api.jar
> needs to be in your CLASSPATH.
>
> You should also take a look at the commons fileUpload
> project; http://commons.apache.org/fileupload/
>
> HTH - Bob
>
>
>
>
> ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
--
Kimberly Begley
Re: file upload servlet
Posted by Bob Hall <rf...@yahoo.com>.
--- 10:07PM Wed 27 Feb 2008 Kimberly Begley
<ki...@gmail.com> wrote:
> Hi - I'm trying to compile come java code to upload
> a file but am getting
> errors - it looks like it can't find the
> javax.servlet stuff to import and
> from what I've read online everyone talks about
> having the directory in the
> classpath but I have also read not to mess with my
> classpath - I'm trying to
> compile it from my
> catalina_home/webapps/appname/WEB_INF directory -
> does
> anyone have any suggestions? I'm sure it's obvious
> but I just can't see it.
>
The CLASSPATH warnings are associated with starting
Tomcat - not compiling your java code; servlet-api.jar
needs to be in your CLASSPATH.
You should also take a look at the commons fileUpload
project; http://commons.apache.org/fileupload/
HTH - Bob
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org