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 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿