Win a copy of Head First Android this week in the Android forum!

Renee de Castro

Greenhorn
+ Follow
since Mar 12, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Renee de Castro

Hi Annie!

You're right!

I feel so stupid right now! hehehe

Thanks for the help! It really means a lot!
16 years ago
Hi everyone!

I am trying to upload file(s) by using java servlet. I am using Tomcat 5.5 and Jason Hunter's MultiPartRequest class. I have also created a simple HTML that invokes the servlet.

My problem is whenever i test the program i always get an error.

here is a snippet of the code that im using..

import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;

public class UploadFile extends HttpServlet {
private String dirName;

public void init(ServletConfig config) throws ServletException {
super.init(config);
// read the uploadDir from the servlet parameters
dirName = config.getInitParameter("uploadDir");
if (dirName == null) {
throw new ServletException("Please supply uploadDir parameter");
}
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/plain");

<other part of the code here>


and i have this error message:

exception

javax.servlet.ServletException: Cannot allocate servlet instance for path /servlet/test.UploadFile
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:388)
org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:169)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NoClassDefFoundError: test/UploadFile (wrong name: UploadFile)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1629)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:850)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1299)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1181)
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:369)
org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:169)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

I have already changed my classpath to include cos.jar. But still it doesnt work. So, what i did was put a copy of the jar file into all possible directories..i have put it in TOMCAT\...\web-inf\lib and C:\Program Files\Java\jdk1.5.0_01\bin directories.

Aside from this i have already compiled the UploadFile servlet so i already have the UploadFile class located in TOMCAT\..\web-inf\classes\test directory.. I have the HTML file in the root directory so i am calling the UploadFile class using this code..

<FORM ACTION="../servlet/test.UploadFile" METHOD=POST ENCTYPE="multipart/form-data">
What is your name? <INPUT TYPE=TEXT NAME=submitter> <BR>
Which file to upload? <INPUT TYPE=FILE NAME=file1> <BR>
<INPUT TYPE=SUBMIT>
</FORM>


I've been trying to figure this out for days now and i'm surely getting a bit desperate as days pass by.

I hope somebody can shed some light into this problem..

thanks a lot!
16 years ago
dear david,

thanks for your reply...it worked!




best regards,
renee
16 years ago
hi guys.. im new on this forum so i dont really know if i should post this topic at the Java beginner's thread or here..

Anyway, i am new in studying java and java servlet. i am primarily interested with JBDC and java servlet's interaction and linkage. currently, i am doing some hands-on experiment using microsoft access as my testing database. Here's a snippet of my code..(warning: they may look really crude..but i hope you will bear with my limited coding experience using servlet).

I have defined a datasource called 'test' that points to my test database.

// connecting to database

Connection con = null;
Statement stmt = null;
ResultSet rs = null;

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc dbc:test");

stmt = con.createStatement();
ResultSet usrName = null;
String myname = "Renee";
String sqlstmt = "SELECT userID from userlist where username = " + myname;

usrName = stmt.executeQuery(sqlstmt);

while(usrName.next()) {
out.print(usrName.getObject(1).toString());
out.print("\n");
}

A simple 'Select statement' works fine. but as soon as i include the 'where clause' i always get this problem ..java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

Please help...
16 years ago