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

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 10:09
    关注

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

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

报告相同问题?

悬赏问题

  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载