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 2 of 2

Thread: Problem with my jsp code .Need Help Please!!!

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

    Default Problem with my jsp code .Need Help Please!!!

    I ve been writing a jsp code.But when redirecting from one page to another page,the browser shows the page code instead of the intended application.Can anybody tell me what error have I done?

    index.html

     
    <!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="SaveData.jsp">
     <input type="submit" value="Collect Data!">
    </FORM>
    </body>
    </html>


    SaveData.jsp

     
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <jsp:useBean id="collectdata" class="collectdata.DataUpload" scope="session"/> 
    <jsp:setProperty name="collectdata" property="*"/>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
     
    </head>
    <body>
    <A HREF="AfterUpload.jsp">Continue</A>
    </body>
    </html>

    AfterUpload.jsp

     
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <jsp:useBean id="collectdata" class="collectdata.DataUpload" scope="session"/> 
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Data Uploaded</title>
    </head>
    <body>
    <%= collectdata.uploadData() %>
    </body>
    </html>

    DataUpload.java

     
     
    package collectdata;
     
     
    import java.net.*;
    import java.sql.*;
    import java.util.List;
    //import java.util.Scanner;
    import org.dom4j.io.SAXReader;
    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.Node;
     
    public class DataUpload {
     
    	public String uploadData()
    	{
    		URL myURL = null;
    		SAXReader xmlReader = new SAXReader();
     
    		/*connecting to the database*/
     
    		Connection conn = null;
     
    		try
    		{
     
     	   		System.out.println("Connecting to Database");
     	   		String userName="root";
     	   		String password = "manutd";
     	   		String url = "jdbc:mysql://localhost/surya";
     	   		//System.out.println(userName+password);
     	   		Class.forName ("com.mysql.jdbc.Driver").newInstance ();
     	   		conn = DriverManager.getConnection (url, userName, password);
     	   		System.out.println ("Database connection established");
     	   		System.out.println("Creating Language Table\n");
     	   		Statement lang=conn.createStatement();
     	   		lang.executeUpdate ("DROP TABLE IF EXISTS language;");
     	   		lang.execute("CREATE TABLE language (lang_code VARCHAR(10) NOT NULL,PRIMARY KEY(lang_code),languages VARCHAR(15));");
     	   		lang.execute("insert into language (lang_code,languages) values ('AR','Arabic'),('EN','English'),('FR','French'),('ES','Spanish'),('RU','Russian'),('ZH','Chinese');");
     	   		System.out.println("Language Table Created");
     
    		}
    		catch (Exception e)
    		{
    			System.err.println (e+"Cannot connect to database server");
    		}
     
     
     
    	/****************************************************************************************************************************************/
     
    		String addr = "http://www.fao.org/countryprofiles/geoinfo/ws/allCountries/EN/";
     
     
    		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) 
    		{
    			e.printStackTrace();
    		}
     
     
    		String xpathExpression = "/Data/self_governing";
    		// Get the list of nodes on given xPath
    		List<? extends Node> nodes = feed.selectNodes(xpathExpression);
     
    		Statement s = null;
    		try 
    		{
    			System.out.println("Creating country table" );
    			s = conn.createStatement ();
    			s.executeUpdate ("DROP TABLE IF EXISTS country_details");
    			s.executeUpdate ("CREATE TABLE country_details(codeISO3 VARCHAR(40) NOT NULL,PRIMARY KEY(codeISO3),codeISO2  VARCHAR(40),Full_name VARCHAR(50),Off_Name VARCHAR(50),Short_Name VARCHAR(50),FAO_Members VARCHAR(50),codeUN VARCHAR(10),codeFAOTERM VARCHAR(10),codeAGROVOC VARCHAR(10),codeFAOSTAT VARCHAR(10),codeUNDP VARCHAR(10),codeGAUL VARCHAR(10),codeDBPediaID VARCHAR(50),codeURI VARCHAR(50),border_countries VARCHAR(60) DEFAULT '',MaxLat FLOAT,MinLat FLOAT,MaxLong FLOAT,MinLong FLOAT,capital VARCHAR(60),population VARCHAR(10),area VARCHAR(10),HDI VARCHAR(10),GDP VARCHAR(10));");
    			System.out.println("Country table created");
    			//System.out.println(s+"   Created\n");
     
    		}
    		catch (SQLException e1) 
    		{
    			// TODO Auto-generated catch block
    			e1.printStackTrace();
    			System.out.println("Not created\n");
    		}
     
    		int y=1;
    		for (Node node : nodes) 
    		{
    			Node codeISO3= node.selectSingleNode("codeISO3");
    			Node codeISO2 = node.selectSingleNode("codeISO2");
    			Node off_name = node.selectSingleNode("nameOfficialEN");
    			Node shortname = node.selectSingleNode("nameShortEN");
    			Node namelist = node.selectSingleNode("nameListEN");
    			Node fao = node.selectSingleNode("FAO_MEMBERS");
    			try 
    			{
            			s=conn.createStatement();
            			System.out.println("Going for the "+y+"country\n");	
    					System.out.println(codeISO3.getText());
    					System.out.println("INSERT INTO country_details VALUES ('"+codeISO3.getText()+"','"+codeISO2.getText()+"','"+off_name.getText()+"','"+shortname.getText()+"','"+namelist.getText()+"','"+fao.getText()+"');");
            			int count = s.executeUpdate ("INSERT INTO country_details (codeISO3,codeISO2,Full_name,Off_Name,Short_Name,FAO_Members) VALUES ('"+codeISO3.getText()+"','"+codeISO2.getText()+"','"+off_name.getText()+"','"+shortname.getText()+"','"+namelist.getText()+"','"+fao.getText()+"');");
            			System.out.println (count + " rows were inserted");
            			y++;
    			}
    			catch (SQLException e) 
    			{
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    			try
    			{
    				s.close ();
    			}
    			catch (SQLException e) 
    			{
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
     
     
     
    		}
    		String temp="Updated";
    		return temp;
    	}
     
    }
    Last edited by ur2cdanger; October 21st, 2011 at 05:16 PM. Reason: Wrong Tags


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    42
    My Mood
    Sneaky
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Problem with my jsp code .Need Help Please!!!

    Return a string from your pagecode which matches a navigation rule in your faces config, the serverlet interprites this as a redirection and will load that page.

Similar Threads

  1. I have a problem in my JSP code
    By abhiM in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 12th, 2011, 04:22 AM
  2. I have a problem with my code I think
    By byrne in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 12th, 2011, 04:18 AM
  3. problem in my code
    By dhruvguys in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2011, 05:18 AM
  4. What is the Problem With This Code?
    By olufemi1712 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 18th, 2011, 09:05 AM
  5. problem with code
    By Imeri0n in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 25th, 2011, 07:06 AM