• Post Reply Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException  RSS feed

 
Muhammad Usman
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i m getting noClassfoundexception while compiling the classq.
if i do this question by public void main method, then i m not getting any exception and result are okay. but in servlet i m getting the exception
why ?

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class p extends HttpServlet implements Serializable {

public void doGet(HttpServletRequest request , HttpServletResponse response) throws
ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

try
{
ObjectOutputStream objectOut = new ObjectOutputStream(new FileOutputStream ("UsersA.dat"));
objectOut.writeObject("usman");
objectOut.writeObject("aqib");
objectOut.writeObject("maleehausman");
objectOut.flush();
objectOut.close();
}

catch (IOException e1)
{System.out.println(" IOexception");}
}
}

mport javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class q implements Serializable {
//static final long serialVersionUID = 7110175216435025451L;
public void doGet(HttpServletRequest request , HttpServletResponse response) throws
ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try {
ObjectInputStream objectIn = new ObjectInputStream( new FileInputStream ("UsersA.dat"));
String a = (String)objectIn.readObject();
String b = (String)objectIn.readObject();
String c = (String)objectIn.readObject();
objectIn.close();}
catch (IOException e)
{System.out.println ("exception occured");}
}
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is really a compiling problem then you need to look into your classpath settings. See the docs/tooldocs/findingclasses.html file in your JDK installation.
If this is a servlet execution problem you may be running into a peculiarity of Tomcat and some other servers. Servlet classes that are NOT in a package are not located correctly, try putting your class in a package and putting the compiled class files in the appropriate path under WEB-INF/classes
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!