为了账号安全,请及时绑定邮箱和手机立即绑定

Tomcat有异常,运行后有报错(注释dopost代码后报错消失)

七月 27, 2015 4:24:00 下午 org.apache.coyote.AbstractProtocol destroy

信息: Destroying ProtocolHandler ["ajp-nio-8009"]

七月 27, 2015 4:24:00 下午 org.apache.coyote.AbstractProtocol destroy

严重: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]

java.lang.NullPointerException

at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:302)

at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:473)

at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:818)

at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:532)

at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)

at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)

at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:588)

at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)

at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:859)

at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)

at org.apache.catalina.startup.Catalina.start(Catalina.java:629)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)

附上自己的servlet:

package com.imooc.servlet;


import com.imooc.po.TextMessage;

import com.imooc.util.CheckUtil;

import com.imooc.util.MessageUtil;


import java.util.Date;

import java.util.Map;

import java.io.IOException;

import java.io.PrintWriter;


import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import org.dom4j.DocumentException;




public class Wechatservlet extends HttpServlet {

@Override

protected void doGet(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException {

String signature = req.getParameter("signature");

String timestamp = req.getParameter("timestamp");

String nonce = req.getParameter("nonce");

String echostr = req.getParameter("echostr");

PrintWriter out = resp.getWriter();

if(CheckUtil.checkSignature(signature, timestamp, nonce)){

out.print(echostr);

}else{

System.out.println("校验失败,请从新尝试");

}

}


@Override

protected void doPost(HttpServletRequest req, HttpServletResponse resp)

            throws ServletException, IOException {

        // TODO Auto-generated method stub

        

            req.setCharacterEncoding("UTF-8");

            resp.setCharacterEncoding("UTF-8");

            PrintWriter out = resp.getWriter();

            try {

            Map<String, String> map = (Map<String, String>) MessageUtil.xmlToMap(req);


                 

                String fromUserName = map.get("ToUserName");

                String toUserName = map.get("FromUserName");

                String createTime = map.get("CreateTime");

                String msgType = map.get("MsgType");

                String content = map.get("Content");

                String msgId = map.get("MsgId");

                 

                String message =null;

                if("text".equals(msgType)){

    TextMessage text = new TextMessage();

    text.setToUserName(toUserName);

    text.setFromUserName(fromUserName);

                    text.setMsgType("test");

                    text.setCreateTime(new Date().getTime());

                    //text.setMsgId(msgId);

                    text.setContent("您发送的消息是"+content);

    message = MessageUtil.textMassagetoXml(text);

                }

                 

                System.out.println(message);

                out.print(message);

            } catch (DocumentException e) {

                // TODO Auto-generated catch block

                e.printStackTrace();

            }finally{

                out.close();

            }

             

        }

        

}


正在回答

1 回答

dopost里面的代码写错了,只是个空指针异常

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

Tomcat有异常,运行后有报错(注释dopost代码后报错消失)

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号