doGet() throws NamingException报错

做一个通过JNDI查找资源的小练习,Context = new InitialContext(),发现NamingException异常,eclipse编辑器只有catch的提示,没有throws的提示,强行在doGet()方法后throws NamingException会报"Exception NamingException is not compatible with throws clause in HttpServlet.doGet(HttpServletRequest, HttpServletResponse)"。

原因:查看HttpServlet中的doGet方法源码,

根据方法重写的原则,子类重写父类方法时,抛出的异常不能超过父类的范畴,因此在本例中,只能throws ServletException和IOEXception,其他异常必须catch使得编译通过。

时间: 2024-10-18 15:13:04

doGet() throws NamingException报错的相关文章

响应自己写的报错信息

import java.io.IOException;import java.io.PrintWriter; import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpS

为什么这个地方用重定向会报错.只能用 服务器跳转?? 为什么我加了过滤器,还是能直接登陆 servlet

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String username= request.getParameter("username"); HttpSession session = request.

springboot 1.5.x 使用tomcat8设置cookie的domain以dot开头报错

"C:\Program Files\Java\jdk1.7.0_75\bin\java" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2017.1.4\lib\idea_rt.jar=61656:C:\Program Files\JetBrains\IntelliJ IDEA

解决tomcat报错javax.imageio.IIOException: Can't create output stream!

启动tomcat catalina.out报错如下,登陆的时候无法显示验证码 2017-06-09 11:23:06,628 DEBUG org.springframework.web.servlet.DispatcherServlet 845 - DispatcherServlet with name 'spring-mvc' processing GET request for [/data-analysis/kaptchaImage.do]2017-06-09 11:23:06,629 D

Android4.4.4 GZIPOutputStream报错:Stream error

在android 4.4.4 机器上使用网友提供的GZipUtils方法进行GZip压缩,但是会一直报错Stream error.错误位置: public static void compress(InputStream is, OutputStream os) throws Exception { GZIPOutputStream gos = new GZIPOutputStream(os); int count; byte data[] = new byte[BUFFER]; while (

fetch 报错 Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body. 在"窗口"上执行"取"失败:GET / get方法的请求不能有正文. GET requests can't have a request body, you can't make them have one. GET requests only retrieve data,

Linux进行AES加密每次结果都不一致并且解密失败报错

1. 现象 windows操作系统下进行"123456"的AES加密 encrypted message is below : QLNYZyjRnKF/zxAjzDt/lw== decrypted message is below : 123456 阿里云服务器,同样是"123456"的密码,每次加密结果都不一样,且不是QLNYZyjRnKF/zxAjzDt/lw==,解密是报错的 2.解决方法 经过检查之后,定位在生成KEY的方法上,如下: public stat

用java运行Hadoop程序报错:org.apache.hadoop.fs.LocalFileSystem cannot be cast to org.apache.

用java运行Hadoop例程报错:org.apache.hadoop.fs.LocalFileSystem cannot be cast to org.apache.所写代码如下: package com.pcitc.hadoop; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.h

freemarker报错之九

1.错误描述 五月 30, 2014 11:52:04 下午 freemarker.log.JDK14LoggerFactory$JDK14Logger error 严重: Template processing error: "Can't convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime bu