org.apache.catalina.core.StandardWrapperValve invoke的解决办法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ZZY1078689276/article/details/46224839

故障码:

Servlet.service() for servlet servletAction threw exception
java.lang.NullPointerException
	at com.dbdao.mysql.mySqlConnection.getClose(mySqlConnection.java:173)
	at com.service.stuInfoService.delete(stuInfoService.java:109)
	at com.action.servletAction.delete(servletAction.java:374)
	at com.action.servletAction.doPost(servletAction.java:79)

网上查找的解决办法:


1.servlet或jsp中,重复调用response的 getOutputStream(),response.getWriter()方法。


2.form表单里没有 method="post" action=""参数。


3.看JDBC操纵数据库的代码,仔细看,例如调用的对象的属性为null。


Connection conn=null; 之后之就调用了conn的方法。


        以上三点我发现写的太笼统,容易让人摸不着头脑,不过经过查找,我终于发现自己代码的错误的地方了,原来是关闭数据库的连接没经过判断,直接就关闭了,这是我的故障源代码,现我将其贴出。


错误源代码:

public void getClose() {  
        // TODO Auto-generated method stub  
          
        //关闭结果集  
        try {  
              
            //结果集关闭方法  
            rs.close();  
              
        } catch (SQLException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }finally{  
              
            //关闭声明的sql语句  
            try {  
                  
                //关闭声明的sql语句方法  
                pstmt.close();  
                  
            } catch (SQLException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
            }finally{  
                  
                //卸载驱动  
                try {  
                      
                    //驱动卸载方法  
                    con.close();  
                      
                } catch (SQLException e) {  
                    // TODO Auto-generated catch block  
                    e.printStackTrace();  
                }  
                  
            }  
        }  
      
    }  

        这知道,虽然在JavaWeb中报错很明显,直接以错误页面的形式满屏显示,但是在Java项目中则并不明显,比如说我一直用junit进行程序代码测试,由于我关注的焦点在控制台,控制台中的内容完全按照我写的代码在运行,而junit的报错却偏偏容易被忽略,因为自己的程序只写了一部分,不全很正常,而junit又恰恰只是测试了这不全代码的可运行的一部分,所以说这里的报错往往很难被注意到。


下面是改正后的代码:

 /* 
     * 关闭方法 
     * */  
    public void getClose() {  
        // TODO Auto-generated method stub  
          
        //关闭结果集  
        try {  
              
            //结果集关闭方法  
            if(rs!=null){  
                  
                rs.close();  
                  
            }  
              
        } catch (SQLException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }finally{  
              
            //关闭声明的sql语句  
            try {  
                  
                //关闭声明的sql语句方法  
                if(pstmt!=null){  
                      
                    pstmt.close();  
                      
                }  
                  
            } catch (SQLException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
            }finally{  
                  
                //卸载驱动  
                try {  
                      
                    //驱动卸载方法  
                    if(con!=null){  
                          
                        con.close();  
                          
                    }  
                      
                } catch (SQLException e) {  
                    // TODO Auto-generated catch block  
                    e.printStackTrace();  
                }  
                  
            }  
        }  
      
    }  

        还有比较容易错的地方是页面带参数进行跳转,由于跳转之后的页面本身也要执行一部分sql语句,比如说进行添加、修改、删除等操作后就自动跳转到新页面进行查询,整个过程是自动的,此时就有可能存在参数丢失的情况,所以说在这里也经常会出现该错误。


总之,出现该错误的地方往往是连接的环节,在关闭连接之前一定要判断连接是否已关闭再执行关闭连接操作,在连接调用之前也要判断连接的东西是否存在。









阅读更多
换一批

org.apache.catalina.core.StandardWrapperValve invoke 菜鸟求救!

03-02

2012-3-2 19:21:07 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet default threw exceptionrnjava.lang.IllegalStateExceptionrn at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)rn at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:821)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:533)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619)rnrnrn以上为我疯狂刷新我的注册页面时就会出现的错误信息.rn在网上找了很久,应该为以下错误原因.rn1.servlet或jsp中,重复调用response的 getOutputStream(),response.getWriter()方法rn2.form表单里没有 method="post" action=""参数rn3.看JDBC操纵数据库的代码,仔细看,例如调用的对象的属性为null。rn就刷新来说,应该是原因1.rn我的注册页面里有 <%=....%>等默认的Write输出语句.注册页面也用到了验证码...取验证码时是从struts的一个action取的 里面输出图片用了 java.io.InputStream .rn我为了不让writer和stream冲突,把所有的jsp输出语句都注释掉了...可还是有错误..代码太多..贴不出来..我就想知道,高手们是如何解决.Writer和Stream两个流都要用时产生的问题的.

struts2 验证码报错 org.apache.catalina.core.StandardWrapperValve invoke

07-24

此代码生成一个4位的随机数,但是快速刷新是报错org.apache.catalina.core.StandardWrapperValve invokern详细的代码和错误提示如下:rnrn[code=Java]rnpackage com.xjdnw.utility;rnrnimport java.awt.Color;rnimport java.awt.Font;rnimport java.awt.Graphics;rnimport java.awt.image.BufferedImage;rnimport java.io.ByteArrayInputStream;rnimport java.io.ByteArrayOutputStream;rnimport java.io.IOException;rnimport java.util.Random;rnimport javax.imageio.ImageIO;rnimport javax.imageio.stream.ImageOutputStream;rnimport org.springframework.stereotype.Component;rnrnimport com.opensymphony.xwork2.ActionContext;rnimport com.opensymphony.xwork2.ActionSupport;rnrn@Component("Validatecode")rnpublic class Validatecode extends ActionSupport rnrn private static final long serialVersionUID = 7190523148768780483L;rn private ByteArrayInputStream image;// 图像rn private String str;// 验证码rnrn private Validatecode() rn init();// 初始化属性rn rnrn /*rn * 取得RandomNumUtil实例rn */rn public static Validatecode Instance() rn return new Validatecode();rn rnrn /*rn * 取得验证码图片rn */rn public ByteArrayInputStream getImage() rn return this.image;rn rnrn /*rn * 取得图片的验证码rn */rn public String getString() rn return this.str;rn rnrn private void init() rn // 在内存中创建图象rn int width = 60, height = 20;rn BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);rn // 获取图形上下文rn Graphics g = image.getGraphics();rn // 生成随机类rn Random random = new Random();rn // 设定背景色rn g.setColor(getRandColor(200, 250));rn g.fillRect(0, 0, width, height);rn // 设定字体rn g.setFont(new Font("Times New Roman", Font.PLAIN, 18));rn // 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到rn g.setColor(getRandColor(160, 200));rn for (int i = 0; i < 155; i++) rn int x = random.nextInt(width);rn int y = random.nextInt(height);rn int xl = random.nextInt(12);rn int yl = random.nextInt(12);rn g.drawLine(x, y, x + xl, y + yl);rn rn // 取随机产生的认证码(6位数字)rn String sRand = "";rn for (int i = 0; i < 4; i++) rn String rand = String.valueOf(random.nextInt(10));rn sRand += rand;rn // 将认证码显示到图象中rn g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));rn // 调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成rn g.drawString(rand, 13 * i + 6, 16);rn rn // 赋值验证码rn this.str = sRand;rnrn // 图象生效rn g.dispose();rn ByteArrayInputStream input = null;rn ByteArrayOutputStream output = new ByteArrayOutputStream();rn rn try rn ImageOutputStream imageOut = ImageIO.createImageOutputStream(output);rn ImageIO.write(image, "JPEG", imageOut);rn imageOut.close();rn input = new ByteArrayInputStream(output.toByteArray());rn this.image = input;/* 赋值图像 */rn rn catch (Exception e) rn System.out.println("Validatecode Error:" + e.toString());rn finallyrn if(input!=null)rn try rn input.close();rn catch (IOException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn if(output!=null)rn try rn output.close();rn catch (IOException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn rn rnrn rn rnrn /*rn * 给定范围获得随机颜色rn */rn private Color getRandColor(int fc, int bc) rn Random random = new Random();rn if (fc > 255)rn fc = 255;rn if (bc > 255)rn bc = 255;rn int r = fc + random.nextInt(bc - fc);rn int g = fc + random.nextInt(bc - fc);rn int b = fc + random.nextInt(bc - fc);rn return new Color(r, g, b);rn rnrn private ByteArrayInputStream inputStream;rnrn public String execute() throws Exception rn Validatecode rdnu = Instance();rn setInputStream(rdnu.getImage());rn ActionContext.getContext().getSession().put("Validatecode", getString());rn return SUCCESS;rn rnrn public void setInputStream(ByteArrayInputStream inputStream) rn this.inputStream = inputStream;rn rnrn public ByteArrayInputStream getInputStream() rn return inputStream;rn rnrnrnrn[/code]rnrnrn2010-7-24 16:54:35 org.apache.catalina.core.StandardWrapperValve invokern严重: Servlet.service() for servlet default threw exceptionrnjava.lang.IllegalStateExceptionrn at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407)rn at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:752)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:505)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619)

org.apache.catalina.core.StandardWrapperValve invoke困扰好久了

07-19

下面是错误rn### Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.chens.web.datareprot.persistence.InsertDataDB2Mapper.insertDB2Datasrn### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.chens.web.datareprot.persistence.InsertDataDB2Mapper.insertDB2Datasrn DEBUG [2016-07-19 15:39:25,525] org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver - Resolving exception from handler [public int com.chens.web.datareprot.web.controller.InsertDataController.insertDataExcute(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.lang.Exception]: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: rn### Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.chens.web.datareprot.persistence.InsertDataDB2Mapper.insertDB2Datasrn### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.chens.web.datareprot.persistence.InsertDataDB2Mapper.insertDB2Datasrn DEBUG [2016-07-19 15:39:25,525] org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver - Resolving exception from handler [public int com.chens.web.datareprot.web.controller.InsertDataController.insertDataExcute(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.lang.Exception]: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: rn### Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.chens.web.datareprot.persistence.InsertDataDB2Mapper.insertDB2Datasrn### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.chens.web.datareprot.persistence.InsertDataDB2Mapper.insertDB2Datasrn DEBUG [2016-07-19 15:39:25,526] org.springframework.web.servlet.FrameworkServlet - Could not complete requestrn org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: rn### Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.chens.web.datareprot.persistence.InsertDataDB2Mapper.insertDB2Datasrn### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.chens.web.datareprot.persistence.InsertDataDB2Mapper.insertDB2Datasrn at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)rn at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)rn at com.sun.proxy.$Proxy27.insert(Unknown Source)rn at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240)rn at com.chens.web.datareprot.persistence.impl.InsertDataDB2MapperImpl.insertDB2Datas(InsertDataDB2MapperImpl.java:17)rn at com.chens.web.datareprot.service.impl.InsertDataDB2ServiceImpl.insertDataJson(InsertDataDB2ServiceImpl.java:126)rn at com.chens.web.datareprot.service.impl.InsertDataDB2ServiceImpl$$FastClassBySpringCGLIB$$414a0f7f.invoke()rn at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)rn at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)rn at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)rn at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)rn at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)rn at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)rn at com.chens.web.datareprot.service.impl.InsertDataDB2ServiceImpl$$EnhancerBySpringCGLIB$$cae86f2b.insertDataJson()rn at com.chens.web.datareprot.web.controller.InsertDataController.insertDataExcute(InsertDataController.java:66)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:606)rn at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)rn at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)rn at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)rn at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)rn rn

没有更多推荐了,返回首页