写的servlet怎么老出错?

chineseyounger 2004-09-08 09:36:24
本来想显示网页,程序如下:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.http.HttpServlet;

public class HelloServlet extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html><head><title>the first</title></head>");
out.println("</body></html>");
}
}
但是显示却出现了
Error Message: Failed to load target servlet [HelloServlet]
Error Code: 500
Target Servlet: HelloServlet
Error Stack:
java.lang.ClassNotFoundException: HelloServlet
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:325)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:296)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:296)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.ReloadableClassLoader.loadClass(ReloadableClassLoader.java:66)
at java.beans.Beans.instantiate(Beans.java:196)
at java.beans.Beans.instantiate(Beans.java:57)
at com.ibm.servlet.engine.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:148)
at com.ibm.servlet.engine.webapp.WebAppServletManager.getServletReference(WebAppServletManager.java:287)
at com.ibm.servlet.engine.webapp.WebApp.getServletReference(WebApp.java:354)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcherInfo.calculateInfo(WebAppRequestDispatcherInfo.java:167)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcherInfo.<init>(WebAppRequestDispatcherInfo.java:51)
at com.ibm.servlet.engine.webapp.WebApp.getRequestDispatcher(WebApp.java:1145)
at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:179)
at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:122)
at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:323)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:252)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
不知错到哪儿?谢谢各位给与解答!!!
...全文
53 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Gooing 2004-09-08
没有配置吧?
另外,那个out出的html少了<body> 诶
回复
zhlmmc 2004-09-08
用servlet要配置环境的,强烈建议用JBuilder之类的IDE来写jsp,这样可以省去很多配置的麻烦。如果想学也可以先看看这些IDE是怎么配置的。
回复
step123 2004-09-08
你配置环境可能出错了,说说你的配置环境、路径都设好没?
回复
chineseyounger 2004-09-08
我是做ejb测试的!我把servlet和helloHome.java、hello.java、helloBean.java放在一起的.我意运行就出错!不知道为什么?servlet原程序如下:
package use.ejb;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.math.BigDecimal;
import javax.ejb.*;
import javax.ejb.HomeHandle;
import javax.naming.InitialContext;
import javax.naming.Context;
import javax.servlet.http.HttpServlet;

public class HelloServlet extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html><head><title>the first EJB</title></head>");
//out.println("<body>ddddd</body>");
try {
Context ctx = new InitialContext();
Object objRef = ctx.lookup("java:jdbc/xx");
//主接口
HelloSessionHome home =
(HelloSessionHome) javax.rmi.PortableRemoteObject.narrow(
objRef,
HelloSessionHome.class);
//组件接口
HelloSession bean = home.create();
out.println(bean.gethello());
} catch (javax.naming.NamingException ne) {
out.println("Naming Exception caught:" + ne);
ne.printStackTrace(out);
} catch (javax.ejb.CreateException ce) {
out.println("Create Exception caught:" + ce);
ce.printStackTrace(out);
} catch (java.rmi.RemoteException re) {
out.println("Remote Exception caught:" + re);
re.printStackTrace(out);
}
out.println("</body></html>");
}
}
////////////////////////
给出的错误信息是:
Original Exception:
Error Message: Failed to load target servlet [HelloServlet]
Error Code: 500
Target Servlet: HelloServlet
Error Stack:
java.lang.ClassNotFoundException: HelloServlet
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:325)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:296)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.CompoundClassLoader.loadClass(CompoundClassLoader.java:296)
at java.lang.ClassLoader.loadClass(ClassLoader.java:257)
at com.ibm.ws.classloader.ReloadableClassLoader.loadClass(ReloadableClassLoader.java:66)
at java.beans.Beans.instantiate(Beans.java:196)
at java.beans.Beans.instantiate(Beans.java:57)
at com.ibm.servlet.engine.webapp.WebAppServletManager.loadServlet(WebAppServletManager.java:148)
at com.ibm.servlet.engine.webapp.WebAppServletManager.getServletReference(WebAppServletManager.java:287)
at com.ibm.servlet.engine.webapp.WebApp.getServletReference(WebApp.java:354)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcherInfo.calculateInfo(WebAppRequestDispatcherInfo.java:167)
at com.ibm.servlet.engine.webapp.WebAppRequestDispatcherInfo.<init>(WebAppRequestDispatcherInfo.java:51)
at com.ibm.servlet.engine.webapp.WebApp.getRequestDispatcher(WebApp.java:1145)
at com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:179)
at com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
at com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:122)
at com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
at com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:323)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:252)
at com.ibm.ws.util.CachedThread.run(ThreadPool.java:122)
////////////////
我也配置了不知道哪儿的问题?
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-08 09:36
社区公告
暂无公告