Im getting an error message when I run this JSP Code.Can anybody clear me about this?
Code :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.util.List" %>
<%@ page import="org.dom4j.io.SAXReader" %>
<%@ page import="org.dom4j.Document" %>
<%@ page import="org.dom4j.DocumentException" %>
<%@ page import="org.dom4j.Node" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<FORM METHOD=GET ACTION="findcountry.jsp">
City ? <INPUT TYPE=TEXT NAME=City SIZE=20>
Longitude ? <INPUT TYPE=TEXT NAME=longitude SIZE=20>
Latitude ? <INPUT TYPE=TEXT NAME=latitude SIZE=20>
<P><INPUT TYPE=SUBMIT>
<h1><% out.println("The Given Longitude is "+request.getParameter("longitude")); %></h1>
<h1><% out.println("The Given Latitude is "+request.getParameter("latitude")); %></h1>
<h1><% out.println("The Given City is "+request.getParameter("City")); %></h1>
<%try
{
URL myURL = null;
SAXReader xmlReader = new SAXReader();
Connection conn = null;
String userName="root";
String password = "manutd";
String url = "jdbc:mysql://localhost/surya";
//out.println(userName+password);
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
Statement stmt=conn.createStatement();
String country=null;
String x=request.getParameter("longitude");
String y = request.getParameter("latitude");
float longi = Float.valueOf(x.trim()).floatValue();
float lati = Float.valueOf(y.trim()).floatValue();
String query = "select * from country_details;";
//out.println(query);
String addr = "http://api.geonames.org/neighbourhood?lat=40.78&lng=-73.96&username=demo";
System.out.println(addr);
try
{
myURL = new URL(addr);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
Document feed = null;
try
{
feed = xmlReader.read(myURL);
System.out.println("Entered");
}
catch (DocumentException e)
{
System.out.println("The error here is "+e);
}
try
{
String xpathExpression = "/geonames/neighbourhood/";
System.out.println(xpathExpression);
List<? extends Node> nodes = feed.selectNodes(xpathExpression); /*The Error is here in this line 77 */
Statement s = null;
for (Node node : nodes)
{
Node codeISO2= node.selectSingleNode("countryCode");
Node city = node.selectSingleNode("city");
String e=codeISO2.getText();
String f=city.getText();
%><h1> The Country Code is <% out.println(e); %> and the city is <% out.println(f); %></h1>
<%
}
}
catch(Exception e )
{
System.out.println("Error is "+e);
}
}
catch(Exception e)
{
out.println(e);
}
%>
</FORM>
</body>
</html>
Error is :
SEVERE: Servlet.service() for servlet [jsp] in context with path [/WebServices] threw exception [An exception occurred processing JSP page /findcountry.jsp at line 77
Please help me to resolve the error.