Can anybody correct the code?
Im just learning jsp.So it would be helpful if somebody can correct my code.
JSP Code :
String x=request.getParameter("longitude");
String y = request.getParameter("latitude");
String addr1 = "http://ws.geonames.org/findNearby?lat="+y+"&lng="+x;
try
{
myURL = new URL(addr1);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
Document feed = null;
try
{
feed = xmlReader.read(myURL);
System.out.println("Entered");
}
catch (DocumentException e)
{
e.printStackTrace();
}
try
{
String xpathExpression = "/geonames/geoname/";
Node codeISO2= feed.selectSingleNode(xpathExpression+"countryCode ");
Node countryName = feed.selectSingleNode(xpathExpression+"countryName ");
String e=codeISO2.getText();
String f=countryName.getText();
System.out.println(e+f);
System.out.println("The Country Code is "+e+" and the country is "+f);
}
catch(Exception e )
{
System.out.println("Error is "+e);
}
Error is :
org.apache.jasper.JasperException: An exception occurred processing JSP page /countryfind.jsp at line 76
73: String xpathExpression = "/geonames/geoname/";
74:
75:
76: Node codeISO2= feed.selectSingleNode(xpathExpression+"countryCode ");
77: Node countryName = feed.selectSingleNode(xpathExpression+"countryName ");
78: String e=codeISO2.getText();
79: String f=countryName.getText();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:456)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
Somebody Please Help.Thanks in advance.
Re: Can anybody correct the code?
Wrap your code in highlight tags, like this:
Code :
[highlight=Java] **JAVA CODE HERE** [/highlight]
Wrap your errors in code tags
Code :
[ code] **ERROR HERE** [ /code]
Re: Can anybody correct the code?
Code Java:
**JAVA CODE HERE**
String x=request.getParameter("longitude");
String y = request.getParameter("latitude");
String addr1 = "http://ws.geonames.org/findNearby?lat="+y+"&lng="+x;
try
{
myURL = new URL(addr1);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
Document feed = null;
try
{
feed = xmlReader.read(myURL);
System.out.println("Entered");
}
catch (DocumentException e)
{
e.printStackTrace();
}
try
{
String xpathExpression = "/geonames/geoname/";
[ code] **ERROR HERE**
Node codeISO2= feed.selectSingleNode(xpathExpression+"countryCode ");
Node countryName = feed.selectSingleNode(xpathExpression+"countryName ");
[ /code]
String e=codeISO2.getText();
String f=countryName.getText();
System.out.println(e+f);
System.out.println("The Country Code is "+e+" and the country is "+f);
}
catch(Exception e )
{
System.out.println("Error is "+e);
}
Error is :
org.apache.jasper.JasperException: An exception occurred processing JSP page /countryfind.jsp at line 76
73: String xpathExpression = "/geonames/geoname/";
74:
75:
76: Node codeISO2= feed.selectSingleNode(xpathExpression+"countryCode ");
77: Node countryName = feed.selectSingleNode(xpathExpression+"countryName ");
78: String e=codeISO2.getText();
79: String f=countryName.getText();
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:456)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
Please help!!
Re: Can anybody correct the code?
Sigh, I meant like this
Code Java:
String x=request.getParameter("longitude");
String y = request.getParameter("latitude");
String addr1 = "http://ws.geonames.org/findNearby?lat="+y+"&lng="+x;
try
{
myURL = new URL(addr1);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
Document feed = null;
try
{
feed = xmlReader.read(myURL);
System.out.println("Entered");
}
catch (DocumentException e)
{
e.printStackTrace();
}
try
{
String xpathExpression = "/geonames/geoname/";
Node codeISO2= feed.selectSingleNode(xpathExpression+"countryCode "); //Error is
Node countryName = feed.selectSingleNode(xpathExpression+"countryName "); //here
String e=codeISO2.getText();
String f=countryName.getText();
System.out.println(e+f);
System.out.println("The Country Code is "+e+" and the country is "+f);
}
catch(Exception e )
{
System.out.println("Error is "+e);
}
Error:
Code :
org.apache.jasper.JasperException: An exception occurred processing JSP page /countryfind.jsp at line 76
73: String xpathExpression = "/geonames/geoname/";
74:
75:
76: Node codeISO2= feed.selectSingleNode(xpathExpression+"countryCode ");
77: Node countryName = feed.selectSingleNode(xpathExpression+"countryName ");
78: String e=codeISO2.getText();
79: String f=countryName.getText();
Stacktrace:
Code :
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:567)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:456)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet .java:722)
Re: Can anybody correct the code?
Oh..Im sorry..Can anybody resolve the error?
Re: Can anybody correct the code?
Re: Can anybody correct the code?
Tell me the directory structure, how are you placing the files in it???
Re: Can anybody correct the code?
I have not yet written the JAVA File.All these codes are inside the jsp file itself.
Code Java:
<%@ 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="countryfind.jsp">
Longitude ? <INPUT TYPE=TEXT NAME=longitude VALUE = "9" SIZE=20>
Latitude ? <INPUT TYPE=TEXT NAME=latitude VALUE = "47.3" SIZE=20>
<P><INPUT TYPE=SUBMIT>
<h1><% out.println("The Given Longitude is "+request.getAttribute("longitude")); %></h1>
<h1><% out.println("The Given Latitude is "+request.getAttribute("latitude")); %></h1>
<%try
{
Connection conn = null;
URL myURL = null;
SAXReader xmlReader = new SAXReader();
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="0";
String y="0";
x=request.getAttribute("longitude").toString();
y = request.getAttribute("latitude").toString();
String addr1 = "http://ws.geonames.org/findNearby?lat="+y+"&lng="+x;
System.out.println(x);
System.out.println(y);
System.out.println(addr1);
if(x!=null && y!=null)
{
try
{
myURL = new URL(addr1);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
Document feed = null;
try
{
feed = xmlReader.read(myURL);
System.out.println("Entered");
}
catch (DocumentException e)
{
e.printStackTrace();
}
try
{
String xpathExpression = "/geonames/geoname";
List<? extends Node> nodes = feed.selectNodes(xpathExpression);
Statement s = null;
for (Node node : nodes)
{
Node codeISO2= node.selectSingleNode("countryCode");
Node countryName = node.selectSingleNode("countryName");
String e=codeISO2.getText();
String f=countryName.getText();
System.out.println(e+f);
System.out.println("The Country Code is "+e+" and the country is "+f);
}
}
catch(Exception e )
{
System.out.println("Error is "+e);
}
}
else
{
%> <h1> Please Enter the Latitude and Longitude</h1>
<% }
}
catch(Exception e)
{
System.out.println("Error is "+e);
}
%>
</FORM>
</BODY>
</HTML>
Re: Can anybody correct the code?
Listen man..... You know that jsp is server pages???
And you need some local server or server to exectue the jsp written (java) code.
Do you have any?
If yes, where it is installed?
Where do you place the jsp file in your computer?