Home Answers Viewqa JSP-Servlet read XML file and display it using java servlets

 
 


madhuri
read XML file and display it using java servlets
1 Answer(s)      a year and 11 months ago
Posted in : JSP-Servlet

sir, i can't access Xml which is present in my d drive plz can u should go through my code n tell me the things where i went wrong

java servlet program

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException 
{
    response.setContentType("text/xml");

    FileRead fr = new FileRead();
    FileWrite fw = new FileWrite();


    ResultSet rs=null,rs_path=null;

    String xmlpath;
    response.setHeader("Cache-Control", "no-cache");
    System.out.println("Hai "+request.getParameter("url"));
    String url = request.getParameter("url");
    String userName = request.getParameter("userName");
    String searchPassword = request.getParameter("searchPass");
    System.out.println(userName+" "+searchPassword);
    try
    {

        PrintWriter out = response.getWriter();
       rs = search_pass.execSQL("Select * from Member_Registration where searchpass='"+searchPassword+"' and username='"+userName+"' and FaultSearch=0");

    }if(rs.next())
        {

            tempValue=0;
            rs = bean_obj.execSQL("Select * from feed_url where URL='"+url+"' and username='"+userName+"'");
            System.out.println(rs.next());
            String filename= request.getParameter("FileName");
           filename = filename.replace(":","_");
            xmlpath = "D:/Leo/"+filename+".xml";
            out.println("<p Style='position:Absolute;top:275px;left:660px;font:bold 12pt/14pt Times New Roman;color:#FFFAF0'>"+xmlpath+"</p>");
            if(rs.next())
            {

                rs_path = bean_obj1.execSQL("Select filename from feed_url where url='"+url+"' and username='"+userName+"'");
                rs_path.next();
                String ss =filename; 
                rs_path.getString("FileName");
                System.out.println(ss);
                xmlpath = "D:/Leo/"+ss+".xml";
                String fileContent = fr.fileRead(xmlpath);
                System.out.println(fileContent);
                out.println(fileContent);
            }   
            else
            {
                out.println("New");

                bean_obj.updateSQL("insert into feed_URL(userName,URL,FileName) values('"+userName+"','"+url+"','"+filename+"')");

                readXML = new XmlBean(userName,url); 
                String str = fw.fileWrite(xmlpath,readXML);

system.out.println(str);

            }
            search_update.updateSQL("UPDATE Member_Registration SET FaultSearch=0 WHERE Username='"+userName+"'");
        }

            //System.out.println("Invalid s1234earch Password "+tempValue);
      else
        {
            if(++tempValue>=3)

            {
                search_update.updateSQL("UPDATE Member_Registration SET FaultSearch=1 WHERE Username='"+userName+"'");
                tempValue=0;
                response.sendRedirect("Search_Password_Error_logout.jsp");
                int i=00;
                out.println("Lock");
            }
            else
            {
                out.println("Invalid search Password "+tempValue);
                response.sendRedirect("Search_Password_Error_logout.jsp");
                int i=0;
                out.println("Invalid");
            }

    }
    }
    catch(Exception e)
    {
        System.out.println(e);
    }
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/** Handles the HTTP <code>GET</code> method.
 * @param request servlet request
 * @param response servlet response
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    processRequest(request, response);
}

/** Handles the HTTP <code>POST</code> method.
 * @param request servlet request
 * @param response servlet response
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    processRequest(request, response);
}

/** Returns a short description of the servlet.
 */
public String getServletInfo() {
    return "Short description";
}
// </editor-fold>

}

jsp:

<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%-- The taglib directive below imports the JSTL library. If you uncomment it, you must also add the JSTL library to the project. The Add Library... action on Libraries node in Projects view can be used to add the JSTL 1.1 library. --%> <%-- <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> --%>

Online RSS Reader

    <%
        String usname = (String)session.getAttribute("uname");
        session.setMaxInactiveInterval(-1);
        //out.println(usname);
    %>
    <p  style="position:absolute;font : bold 12pt/14pt Times New Roman;top: 8px;left:650px;">
      <%  
        String name = (String)session.getAttribute("MemberName");
        out.println(name);
        session.setMaxInactiveInterval(-1);
       %>
    </p>
  <body>  
      <form id="main">
    <!--  DIV FOR LOG OUT  -->
    <div style="position:absolute;top:10px;left:800px;cursor:hand;" onclick="logout()">
        <img src="Image/img03.gif" style="height:20px;width:100px;"/>
        <span style="position:absolute;top:0px;left:23px;font-weight:bold">Log Out</span>
    </div>

    <!--  DIV FOR HOME PAGE AND MANAGE SUBSCRIPTION  -->
    <div class="home" id="home" style="position:absolute;top:35px;left:5px;width:980px;height:100px; background-color:#87CEFA;overflow:auto">
        <span style="position:absolute;top:30px;left:70px;font-weight:bold">Check Feed URL :</span>
        <input id="url"  type="text" size="75" style="position:absolute;top:30px;left:230px;"/>
        <span style="position:absolute;top:70px;left:70px;font-weight:bold">Search Password :</span>
        <input id="searchPass" name="searchPass" type="text" size="75" style="position:absolute;top:70px;left:230px;"/>
        <input type="button" onclick="checkXML('<%=usname%>')" size="14" value="Add URL" style="position:absolute;top:45px;left:750px;"/>
        <p style="position:absolute;top:105px;left:100px;font-weight:bold"></p>

         <!--<a id="home1" href="Manage_Feeds.jsp" target="_self" style="position:absolute;top:60px;left:40px;font-weight:bold;text-decoration:none;cursor:hand;">
            <u> Manage Subscription </u>-->

    </div>
        <div id="Rss_Title" style="position:absolute;top:150px;left:2px;padding:0px 0px 0px 0px;background-color:#FFFFFF;" >
        </div>

        <div style="position:absolute;top:10px;left:50px;cursor:hand;" onclick="Search_His('<%=usname%>')">

            <img src="Image/img03.gif" style="height:20px;width:150px;"/>
            <span style="position:absolute;top:0px;left:23px;font-weight:bold">Search History</span>
        </div>

    <div style="position:absolute;top:10px;left:250px;cursor:hand;" onclick="setting('<%=usname%>')">

            <img src="Image/img03.gif" style="height:20px;width:100px;"/>
            <span style="position:absolute;top:0px;left:28px;font-weight:bold">Setting</span>
        </div>
        </form>

 </body>

View Answers

July 30, 2011 at 1:04 PM


Use dom parser..........

import java.io.*;
import org.w3c.dom.*;
import javax.servlet.*;
import javax.xml.parsers.*;
import javax.servlet.http.*;

public class ReadXML extends HttpServlet{ 
    public boolean isTextNode(Node n){
    return n.getNodeName().equals("#text");
    }
        public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        try{
        DocumentBuilderFactory docFactory =  DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
        Document doc = docBuilder.parse("C:/roseindia.xml");
        out.println("<table border=2><tr><th>Name</th><th>Address</th></tr>");
        Element  element = doc.getDocumentElement(); 
        NodeList personNodes = element.getChildNodes(); 
        for (int i=0; i<personNodes.getLength(); i++){
        Node emp = personNodes.item(i);
        if (isTextNode(emp))
         continue;
        NodeList NameDOBCity = emp.getChildNodes(); 
        out.println("<tr>");
        for (int j=0; j<NameDOBCity.getLength(); j++ ){
        Node node = NameDOBCity.item(j);
        if ( isTextNode(node)) 
        continue;
        out.println("<td>"+(node.getFirstChild().getNodeValue())+"</td>");
        } 
        out.println("</tr>");
        }
        out.println("</table>");
        }
        catch(Exception e){
            System.out.println(e);
        }
        }
}









Related Pages:
read XML file and display it using java servlets
read XML file and display it using java servlets  sir, i can't access Xml which is present in my d drive plz can u should go through my code n tell me the things where i went wrong java servlet program protected void
Read XML using Java
of all i need to read xml using java . i did good research in google and came to know...Read XML using Java  Hi All, Good Morning, I have been working.../xmlParsing/java-xml-parsing-using-sax.shtml http://www.roseindia.net/xml/sax
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
how to read this xml file - XML
how to read this xml file  i want to read this xml file using java(using struts2 or using jsp) and i want result as name=admin menu=user... read i have tried lot more , but i am not able to read this xml file
read xml using java
read xml using java  <p>to read multiple attributes and elements from xml in an order.... ex :component name="csl"\layerinterfacefile="poo.c...;   Please visit the following link: Read XML data
How to read text file in Servlets
How to read text file in Servlets  ... file in servlets. In this example we will use the input stream to read the text.... We will read the content of this file and display in the browser.  Get
Retrieve data from xml using servlets
for retrieving the data from xml File using Servlets.   Hi, Do you want to read and parse the XML file in servlet? Please ask your question in detail. Thanks Deepak   Hi, Here is one tutorial: Create XML File using Servlet
servlets
servlets  How to open and read the contents of a text file in servlets?   Please visit the following link: Read text file using Servlet
read xml
read xml   hi all, i want to ask about how to read an xml in java ME.. here is the xml file <data> <value> <struct> <member> <name> User_Name
Read XML in java - XML
Read XML in java  Hi Deepak, I want to read a xml file which have only one element with multiple attributes with same tag name. here is my file... a solution.my java code is given below. import java.io.File; import
xml file reading using java
xml file reading using java  hi deepak I want to read some data from xml file and send that output to particular email address using java   import org.w3c.dom.*; import org.w3c.dom.Node; import javax.xml.parsers.
servlets
of filters. A filter is configured in a web.xml file. The class using...what are filters in java servlets  what are filters in java  ... functionality to the servlets apart from processing request and response paradigm
servlets
servlets  how can I run java servlet thread safety program using... { super.init(config); acct=new account(); try{ File r=new File(?count... destroy() { File r=new File(?counter?); try{ DataOutputStream dout=new
read xml elements
read xml elements  i want read xml data using sax parser in java. but is there any classes or methods to read xml elements
read xml elements
read xml elements  i want read xml data using sax parser in java. but is there any classes or methods to read xml elements
How to Read Excel file Using Java
How to Read Excel file In this section,you will learn how to read excel file data and display on the console.We have used Jakarta POI api... data is then used to display file values on the console. Here is the code
xml file display - XML
code to display the above xml file in tree structure where...xml file display   - - - - ADL SCORM CAM 1.3 - - session3 - Online Instructional Strategies that Affect Learner
How to read value from xml using java?
How to read value from xml using java?  Hi All, I want to read value from following xml using java.. In <Line>,data is in format of key and value pair.. i want to read only values..could u plz help me in this?Thanks
XML parsing using Java - XML
XML parsing using Java  I'm trying to parse a big XML file in JAVA..." in element "MIRate"(THE XML code is below).once he enters coverage rate I need to display initial and renewal rate. Like if he enter all the attribute values starting
What is XML?
it will display the xml file structure as show below: Click here to view invoice.xml XML...: XML file is simple text file with .xml extension. XML file is used..., SMIL, XHTML etc. are created using XML XML is markup language much
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui. seems the problems is all xml tag must be enum. can you suggest me how to read
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui. seems the problems is all xml tag must be enum. can you suggest me how to read
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui. seems the problems is all xml tag must be enum. can you suggest me how to read
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui. seems the problems is all xml tag must be enum. can you suggest me how to read
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui. seems the problems is all xml tag must be enum. can you suggest me how to read
can't read my xml file in java
can't read my xml file in java  i've a xml file like this : <...(); } the codes can't read the xml file bcz i want to append the whole xml in my gui. seems the problems is all xml tag must be enum. can you suggest me how to read
How to read text file in Servlets
; This is detailed java code to connect a jsp page to mysql database and create a table of given... an application directory named 'user' in the Tomcat. Before running this java code...;head> <title>Create table in mysql database using jsp<
Java + XML - XML
java...the attribute value..not sure now how to read the xml file passing...Java + XML  1) I have some XML files, read one xml..." pointing to a hello xml file ..read that file and get the value of the parent
Read Complex XML using DOM/SAX Parser.
Read Complex XML using DOM/SAX Parser.  I have a XML file which is having two types of Items. I want to extract all details of a type only. My XML goes something like this <Movie> <Bollywood> <Actor> Shah Rukh
Read the value from XML in java
Read the value from XML in java  Hi, i have an XML...:/Lakki/PermissionCheck/logs/RevAppserver.log") of log file in order to check the permissions on that file.So how can i read that value. This is little urgent
XML
XML  create flat file with 20 records. Read the records using xml parser and show required details
Read Specific Line from file Using Java
Read Specific Line from file Using Java Here we are going to read a specific line from the text file. For this we have created a for loop to read lines 1... of BufferedReader class read that particular line and display
How to read the .doc/ .docx file in Java Program
How to read the .doc/ .docx file in Java Program  Hi, I am beginner in Java programming language. Can anybody explain How to read .doc file in Java.... This way you can read the .doc or .docx file in Java programming language. Thanks
XML- read Text Mode - Java Error in Windows - reg. - Java Beginners
XML- read Text Mode - Java Error in Windows - reg.  Dear All I'm creating the code as read the XML file in BufferedReader method. Here I pasted the code below:. (*) First read the XML file using FileInputStream
Display image on JSP page using XML
Display image on JSP page using XML   ... display a image on JSP page by using XML.  This example will examine how to parse and expose XML information using the JAXP with a JSP page. This tutorial
XML in java - XML
XML in java  Write a program using SAX that will count the number of occurrences of each element type in an XML document and display them. The document file to be processed should be identified by the first command-line
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
java - XML
This is my XML file then how can read this XML file Using DOM & SAX parsers in java? How can write the same data into XML file using DOM parser? Could you
Get Data From the XML File
Get Data From the XML File       Here you will learn to retrieve data from XML file using SAX parser... C:\vinod\xml\comXML>java EmployeeDetails Enter XML file
Create XML File using Servlet
Create XML File using Servlet   ... file using Servlet  We have created  file XmlServlet.java. It creates XML file with its version and encoding and display a message 'Xml File Created
java servlets - JSP-Servlet
java servlets  how to get the parameter value of input type file using java servlets  Hi, You can use request.getParameter(). In Jsp... display fileName, It displays the file's path you have selected. Thanks
JAXB Create XML File And Get Data From XML
to write the Java Objects into a XML file and unmarshal() method to read XML... using Java Object then we will read that XML data as Java Object again. In this example at first we will create Java Classes to create an XML file using Java
xml
xml  how to creatte html file and validate using java and finally i need get web.xml file
How to read and display data from a .properties file from a jsp page
How to read and display data from a .properties file from a jsp page  I have a .properties file. I have to create a jsp page such that it reads the data from this .properties file and display it in table format. Ex:by using
j2me with xml - Java Beginners
j2me with xml   shahzad.aziz1@gmail.com i am working in j2me and i want to read and display data using xml file. In j2me application KXML PARSER is use to read and display data. When i run my application in ?Wireless
simple code to write an read and write the login detail to a xml file using javascript ( username and password )
simple code to write an read and write the login detail to a xml file using... to write and read the login details (username and password )into a xml file using javascript. (XML database
How to Read a file line by line using BufferedReader?
How to Read a file line by line using BufferedReader?  Hello Java... problem is to find the best way to read the file in Java. I just searched the google... to Read a file line by line using BufferedReader, efficiently and using less memory
How to Split a large XML file using java?
How to Split a large XML file using java?  How can we split a 500MB Xml file?I know how to split xml file after reading the entire document in a file.Here we cannot load the entire file as it is a large file
read from file and store using hash map
read from file and store using hash map  I was stuck with a java project where I have to read a file with two different concepts and store them differently in hashmap. My data file would be something like Adults: Name, xyz
JDOM example in java, How to read a xml file in java.
JDOM example in java, How to read a xml file in java. In this tutorial, we will see how to  read a xml file in java. Code. Student.xml...;     File file = new File(data