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 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题