jiangjixiangjava 2017-08-07 00:55 采纳率: 100%
浏览 2079
已采纳

Tomcat启动报错与HttpClient有关

代码如下
@RequestMapping("/query")
@ResponseBody
public String getCount() {
String LOGINURL = "http://ip/workspace/index.jsp?framed=true";
String HTTPURL = "http://ip/HyperionPlanning/servlet/HspLogOn";
HttpClient http = null;
String userid = "admin";
String token = null;
String sessionId = null;
http = new DefaultHttpClient();
try {

        String url = LOGINURL + "&username=" + userid;
        HttpPost post = new HttpPost(url);

        // post.setHeader("HYPLOGIN", userid);
        HttpResponse response = http.execute(post);
        BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuffer result = new StringBuffer();
        String line;
        while ((line = br.readLine()) != null) {
            result.append(line);
        }
        String string = result.toString();
        // System.out.println(string);
        string = string.substring(0, 2500);
        // System.out.println(string);

        String regex = "sToken.*=.*\"(.+?)\";.*sCSRFToken";
        Pattern p = Pattern.compile(regex);
        Matcher matcher = p.matcher(string);
        while (matcher.find()) {
            token = matcher.group(1);
        }
        post.abort();

        // String mtoken = token.replace("\\n", "\\\n") + "=";
        // System.out.println(mtoken);

        HttpPost posthttp = new HttpPost(HTTPURL);

        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("Application", "FYCWYS"));
        nvps.add(new BasicNameValuePair("isContained", "true"));
        nvps.add(new BasicNameValuePair("isWorkspace", "true"));
        nvps.add(new BasicNameValuePair("LOCALE_LANGUAGE", "zh_CN"));
        nvps.add(new BasicNameValuePair("moduleid", "HyperionPlanning.planning.7"));
        nvps.add(new BasicNameValuePair("themeSelection", "BpmTadpole"));
        nvps.add(new BasicNameValuePair("upk_available", "false"));
        String mtoken = token.replace("\\n", "\\\n") + "=";
        nvps.add(new BasicNameValuePair("sso_token", mtoken));
        posthttp.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse responseSession = http.execute(posthttp);

        posthttp.abort();
        Header[] headers = responseSession.getHeaders("Set-Cookie");
        for (Header header : headers) {
            if (header.toString().contains("SESSIONID")) {
                String str = header.toString();
                // String reg = "Cookie:(.+?);.*path";
                String reg = "JSESSIONID=(.+?);.*path";
                Pattern pattern = Pattern.compile(reg);
                Matcher m = pattern.matcher(str);
                while (m.find()) {
                    sessionId = m.group(1).trim();
                }
            }
        }
        System.out.println(sessionId);

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (UnsupportedOperationException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println(sessionId);
    return  sessionId;
}

启动tomcat 报错
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/http/client/ClientProtocolException但是在public static void main(String[] args) {
oaLoginLimitedServlet a=new oaLoginLimitedServlet();
System.out.println( "打印"+a.getCount());
}调用是正常的

展开全部

  • 写回答

5条回答 默认 最新

  • 王搏 2017-08-07 02:09
    关注

    可能原因是 你在项目设置里导包 Tomcat启动失败 是因为你没在项目目录里把包放进去

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 一部手机能否同时用不同的app进入不同的直播间?
  • ¥15 没输出运行不了什么问题
  • ¥20 输入import torch显示Intel MKL FATAL ERROR,系统驱动1%,: Cannot load mkl_intel_thread.dll.
  • ¥15 点云密度大则包围盒小
  • ¥15 nginx使用nfs进行服务器的数据共享
  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
  • ¥15 51嵌入式入门按键小项目
  • ¥30 海外项目,如何降低Google Map接口费用?
  • ¥15 fluentmeshing
  • ¥15 手机/平板的浏览器里如何实现类似荧光笔的效果
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部