Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Can anybody correct the code?

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Can anybody correct the code?

    Wrap your code in highlight tags, like this:
    [highlight=Java] **JAVA CODE HERE** [/highlight]

    Wrap your errors in code tags
    [ code] **ERROR HERE** [ /code]

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anybody correct the code?

     **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!!

  4. #4
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Can anybody correct the code?

    Sigh, I meant like this
     
    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:
    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)

  5. #5
    Junior Member
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anybody correct the code?

    Oh..Im sorry..Can anybody resolve the error?

  6. #6
    Junior Member
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anybody correct the code?

    Somebody please!!!!

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Can anybody correct the code?

    Tell me the directory structure, how are you placing the files in it???

  8. #8
    Junior Member
    Join Date
    Sep 2011
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anybody correct the code?

    I have not yet written the JAVA File.All these codes are inside the jsp file itself.

     
     
    <%@ 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>

  9. #9
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default 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?

Similar Threads

  1. Can anybody correct the code?
    By ur2cdanger in forum JDBC & Databases
    Replies: 1
    Last Post: October 17th, 2011, 07:07 PM
  2. Is this correct? Tips if any please
    By giga97 in forum Object Oriented Programming
    Replies: 1
    Last Post: October 8th, 2011, 10:03 AM
  3. Replies: 2
    Last Post: August 2nd, 2011, 08:11 AM
  4. I still have errors. Can you PLEASE correct my code?!
    By sam30317 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 6th, 2011, 06:10 AM
  5. [SOLVED] Code is correct, but incorrect output?
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 6th, 2011, 02:32 PM