【发布时间】:2017-11-09 22:11:18
【问题描述】:
我正在尝试使用 tomcat 8.5.23 运行应用程序,但我一遍又一遍地收到相同的错误。每次尝试启动 tomcat 并打开本地主机时,我都会不断收到 HTTP 状态 500 错误。 这是错误:org.apache.jasper.JasperException:在第 [19] 行处理 JSP 页面 [/index.jsp] 时发生异常。这是我的文件(index.jsp 和 IntagramWB.java)
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Web Services">
<meta name="keywords" content="JSP, Bootstap, HTML5">
<!-- including the jQuery file to the bootstrap -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- including the bootstrap file -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<title> My Restful API</title>
<body>
<%@ page import = "com.mywebservices.InstagramWB" %>
<% InstagramWB insta = new InstagramWB(); %>
<% String details = insta.getDetails(); %>
<script>
var name = JSON.parse("<%= details %>");
document.getElementById("name").innerHTML = details.data.full_name;
</script>
<h1 id = "name"> </h1>
<h2>Last place: </h2>
</body>
</html>
我正在尝试从 java 类中调用一个方法。这是我的java文件:
package com.mywebservices;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class InstagramWB
{
public InstagramWB()
{}
public static String getDetails()
{
// Variable for the access token
String accessToken = "269891473.1677ed0.a60ed893764d4c5";
String replyInsta = "";
String jsonInsta = "";
URL url;
HttpURLConnection connection = null;
InputStream is = null;
try
{
// Endpoint to get the details of the user
String endpoint = "https://api.instagram.com/v1/users/self/?access_token="+accessToken;
// establishing the connection to the endpoint
url = new URL(endpoint);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
is = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((replyInsta = reader.readLine()) != null)
{
jsonInsta = replyInsta;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return jsonInsta;
}
}
如果需要,这也是我的文件夹结构。
和例外情况:
【问题讨论】:
-
你编译部署你的类了吗?它必须在
WEB-INF/classes文件夹中。