jcreator 编写一个servlet 报错
packagecom.jiekou;importjavax.servlet.*;importjavax.io.*;importjavax.servlet.*;import...
package com.jiekou;
import javax.servlet.*;
import javax.io.*;
import javax.servlet.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
/**
* @(#)hello.java
*
*
* @author
* @version 1.00 2010/4/22
*/
//这是我的第一个servlet,接口
public class hello implements Servlet{
/**
* Method init
*
*
* @param parm1
*
@throws ServletException
*
*/
//该函数用户初始化servlet(类似于类的构造函数)
//该函数只会被调用一次(当用户第一次访问该servlet是被调用)
public void init(ServletConfig parm1) throws ServletException {
// TODO: Add your code here
System.out.println("init it");
}
/**
* Method getServletConfig
*
*
* @return
*
*/
public ServletConfig getServletConfig() {
// TODO: Add your code here
return null;
}
/**
* Method service
*
*
* @param parm1
* @param parm2
*
@throws ServletException
@throws IOException
*
*/
//这个函数用于处理业务逻辑
//程序员应当把业务逻辑代码写在这里
//当用户每访问该servlet时,都会调用
//req:用于获得客户端(浏览器)的信息
//res:用于向客户端(浏览器)返回信息
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
// TODO: Add your code here
System.out.println("service it");
//从res中得到Printwriter
Printwriter pw=res.getwriter();
pw.println("hello,world");
}
/**
* Method getServletInfo
*
*
* @return
*
*/
public String getServletInfo() {
// TODO: Add your code here
return "";
}
/**
* Method destroy
*
*
*/
//销毁servlet实例(释放内存)
//1.reload 该servlet(webapps)//2.关闭tomcat//3.关机
public void destroy() {
// TODO: Add your code here
System.out.println("destroy!");
}
}
编译后报错:
--------------------Configuration: <Default>--------------------
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myWebSite\WEB-INF\classes\hello.java:5: 软件包 javax.io 不存在
import javax.io.*;
^
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myWebSite\WEB-INF\classes\hello.java:78: 找不到符号
符号: 类 Printwriter
位置: 类 com.jiekou.hello
Printwriter pw=res.getwriter();
^
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myWebSite\WEB-INF\classes\hello.java:78: 找不到符号
符号: 方法 getwriter()
位置: 接口 javax.servlet.ServletResponse
Printwriter pw=res.getwriter();
^
3 错误
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook
Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:D:\PROGRA~1\HP\QUICKT~1\bin\JAVA_S~1\classes;D:\PROGRA~1\HP\QUICKT~1\bin\JAVA_S~1\classes\jasmine.jar
Process completed. 展开
import javax.servlet.*;
import javax.io.*;
import javax.servlet.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
/**
* @(#)hello.java
*
*
* @author
* @version 1.00 2010/4/22
*/
//这是我的第一个servlet,接口
public class hello implements Servlet{
/**
* Method init
*
*
* @param parm1
*
@throws ServletException
*
*/
//该函数用户初始化servlet(类似于类的构造函数)
//该函数只会被调用一次(当用户第一次访问该servlet是被调用)
public void init(ServletConfig parm1) throws ServletException {
// TODO: Add your code here
System.out.println("init it");
}
/**
* Method getServletConfig
*
*
* @return
*
*/
public ServletConfig getServletConfig() {
// TODO: Add your code here
return null;
}
/**
* Method service
*
*
* @param parm1
* @param parm2
*
@throws ServletException
@throws IOException
*
*/
//这个函数用于处理业务逻辑
//程序员应当把业务逻辑代码写在这里
//当用户每访问该servlet时,都会调用
//req:用于获得客户端(浏览器)的信息
//res:用于向客户端(浏览器)返回信息
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
// TODO: Add your code here
System.out.println("service it");
//从res中得到Printwriter
Printwriter pw=res.getwriter();
pw.println("hello,world");
}
/**
* Method getServletInfo
*
*
* @return
*
*/
public String getServletInfo() {
// TODO: Add your code here
return "";
}
/**
* Method destroy
*
*
*/
//销毁servlet实例(释放内存)
//1.reload 该servlet(webapps)//2.关闭tomcat//3.关机
public void destroy() {
// TODO: Add your code here
System.out.println("destroy!");
}
}
编译后报错:
--------------------Configuration: <Default>--------------------
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myWebSite\WEB-INF\classes\hello.java:5: 软件包 javax.io 不存在
import javax.io.*;
^
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myWebSite\WEB-INF\classes\hello.java:78: 找不到符号
符号: 类 Printwriter
位置: 类 com.jiekou.hello
Printwriter pw=res.getwriter();
^
C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\myWebSite\WEB-INF\classes\hello.java:78: 找不到符号
符号: 方法 getwriter()
位置: 接口 javax.servlet.ServletResponse
Printwriter pw=res.getwriter();
^
3 错误
Picked up JAVA_TOOL_OPTIONS: -agentlib:jvmhook
Picked up _JAVA_OPTIONS: -Xrunjvmhook -Xbootclasspath/a:D:\PROGRA~1\HP\QUICKT~1\bin\JAVA_S~1\classes;D:\PROGRA~1\HP\QUICKT~1\bin\JAVA_S~1\classes\jasmine.jar
Process completed. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询