当前位置: 代码迷 >> Java Web开发 >> !在做servlet测试的时候发生异常,抛出错误,内详,多谢
  详细解决方案

!在做servlet测试的时候发生异常,抛出错误,内详,多谢

热度:753   发布时间:2016-04-17 01:32:59.0
在线等 !求助,在做servlet测试的时候发生错误,抛出异常,内详,谢谢
Java code
import java.io.IOException;import java.io.InputStream;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.sun.xml.internal.fastinfoset.sax.Properties;//读取资源文件public class ServletDemo11 extends HttpServlet {    public void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {                InputStream in = this.getServletContext().getResourceAsStream(                "/WEB-INF/classes/db.properties");        Properties props = new Properties();        props.load(in);        String url = props.getProperty("url");        String username = props.getProperty("username");        String password = props.getProperty("password");                System.out.println(url);        System.out.println(username);        System.out.println(password);    }    public void doPost(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        doGet(request, response);    }


抛出了
2012-7-5 16:28:24 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [ServletDemo11] in context with path [/day5] threw exception [Servlet execution threw an exception] with root cause
java.lang.Error: Unresolved compilation problems
The method load(InputStream) is undefined for the type Properties
The method getProperty(String) is undefined for the type Properties
The method getProperty(String) is undefined for the type Properties
The method getProperty(String) is undefined for the type Properties

at cn.itcast.ServletDemo11.doGet(ServletDemo11.java:23)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1815)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)


测试的代码是没错的,看了视频以后自己按着写出来的,
tomcat用的是7的版本
然后lib用的是J2EE1.4的
tomcat的lib也已经指向了,
这样测试的时候还是出了错 请问是什么问题?谢谢!


------解决方案--------------------
import com.sun.xml.internal.fastinfoset.sax.Properties;
你这里Properties的包是不是导入错了。
改成这个试试:
import java.util.Properties;
代码迷推荐解决方案:Servlet.service() for servlet default threw exception,http://www.daimami.com/search?q=181756
  相关解决方案