Parse XML and Output to JSP page

I have a number of XML documents which are all formatted in the same way, just with different information in the fields.
I wish to parse the XML documents using DOM and output them to an XML page.
How would i go about doing this?
If you could write a small example or any websites that you think might help.
Thanks.

I have the parsing working but i cant seem to figure out how to get information out of the parsed document and into variables.
This is a sample of my XML file
<?xml version="1.0"?>
<product code="QB-1226-AB">
     <productName>Professional Floodlights</productName>
     <description>PIR floodlights that are designed for professional installation. A faulty light requiring a return visit will cost far more than a quality light does in the first place. 3 year guarantee.</description>
     <price>120</price>
     <manufacturer>Black and Decker</manufacturer>
</product>I can get the productCode value out without any problems using
String name = attrs.getValue("code");
But if i try the same for any of the others i get null. I can accomplish this using DOM easily but i cant find anything at all about getting values out of it using SAX.
Any help would be greatly appreciated.

Similar Messages

  • Writing XML file from a jsp page

    how can i write a xml file from my jsp and store the values and after sometime, for example when the user clicks on the submit button, i check the values from xml file and compare those values from the data base.
    it means both writing and reading xml file from a jsp page...
    urgent help needed......thanks

    You need some API like XSL or JDOM to read data from/to XML file
    you can get a best tutorial from
    http://www.javaworld.com/javaworld/jw-05-2000/jw-0518-jdom.html
    and
    http://www.javaworld.com/javaworld/jw-07-2000/jw-0728-jdom2.html
    after reading both articals you will be able to do both the tasks

  • How to retrieve data and display in JSP page

    hi,
    i am trying to retrieve data from SQL server 2000 and display in JSP Page. I have already place the codes of the retrieve in the bean file. I wanna ask is that how to display in the JSP page. If possible, can provide example codings for mi to reference?
    Thanks
    Regards,
    shixuan

    HI Tan ,
    I pressume that you wanted to make use of PDK, the code can go like this .
    <b><u>1) JAVA file</u></b>
    import com.sapportals.htmlb.DropdownListBox;
         import com.sapportals.htmlb.InputField;
         import com.sapportals.htmlb.event.Event;
         import com.sapportals.htmlb.page.DynPage;
         import com.sapportals.htmlb.page.PageException;
         import com.sapportals.portal.htmlb.page.JSPDynPage;
         import com.sapportals.portal.htmlb.page.PageProcessorComponent;
         import com.sapportals.portal.prt.component.IPortalComponentRequest;
         import com.sapportals.portal.prt.component.IPortalComponentSession;
         import com.sapportals.portal.prt.component.IPortalComponentContext;
         import java.sql.*;
         public class P_SAP_B_User extends PageProcessorComponent
         * Method          :           getPage()
         * Description      :                         
         * Input Parameters     :     None
         * Returns          :          Object of Class DynPage     
              public DynPage getPage()
                  return new P_SAP_B_UserDynPage();
                }     // end of dynPage()
                public static class P_SAP_B_UserDynPage extends JSPDynPage
                  /* Variable Declaration     */
                   /* Object of bean class P_SAP_B_CreateUser initialised to null */
                       private P_SAP_B_CreateUser createUserBean = null;
                  /* Flags for checking the occurance of Event & Error. */
                  private int iFlag=0;
                  private int iErrFlag=0;
                  /* Variables for storing the information
                          entered by user in each text field */
                  private String sFname;
                  private String sSname;
                  private String sAge;
                  private String sExp;
                  private String sSkill;
                  private String sUnit;
         * Method          :           doInitialization()
         * Description      :                         
         * Input Parameters     :     None
         * Returns          :          None
                  public void doInitialization()
                         IPortalComponentSession componentSession = ((IPortalComponentRequest)getRequest()).getComponentSession();
                         Object o = componentSession.getValue("createUserBean");
                         if(o==null || !(o instanceof P_SAP_B_CreateUser))
                           createUserBean = new P_SAP_B_CreateUser();
                           componentSession.putValue("createUserBean",createUserBean);
                        }     // end of if
                         else
                             createUserBean = (P_SAP_B_CreateUser) o;
                         }     // end of else
                   }//end of doInitialisation()
         * Method          :           onUpdate()
         * Description      :                         
         * Input Parameters     :     object of Event class
         * Returns          :          None
                   public void onUpdate(Event e)throws PageException
                        /*     sets flag to 1 when update button is clicked. */
                        iFlag=1;
         * Method          :           doProcessAfterInput()
         * Description      :                         
         * Input Parameters     :     None
         * Returns          :          None
                  public void doProcessAfterInput() throws PageException
                             InputField ifFirstName = (InputField) getComponentByName("FirstName");
                             InputField ifSecondName = (InputField) getComponentByName("SecondName");
                             InputField ifAge = (InputField) getComponentByName("Age");
                             InputField ifExp = (InputField) getComponentByName("Exp");
                             InputField ifSkill = (InputField) getComponentByName("Skill");
                             DropdownListBox dlbUnit = (DropdownListBox) getComponentByName("Unit");
                             int iAge,iExp;
                             IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();
                            IPortalComponentContext myContext = request.getComponentContext();
                             P_SAP_B_CreateUser myNameContainer = (P_SAP_B_CreateUser) myContext.getValue("createUserBean");
                             if(ifFirstName != null)
                                  this.sFname = ifFirstName.getValueAsDataType().toString() ;
                             }     // end of if
                             if(ifSecondName!= null)
                                  this.sSname = ifSecondName.getValueAsDataType().toString() ;
                             }      // end of if
                             if(ifAge!= null)
                                  this.sAge = ifAge.getValueAsDataType().toString() ;
                             }     // end of if
                             if(ifExp!= null)
                                  this.sExp = ifExp.getValueAsDataType().toString() ; 
                             }     // end of if                         
                             if(ifSkill != null)
                                  this.sSkill = ifSkill.getValueAsDataType().toString() ;          
                             }     // end of if
                             if(dlbUnit != null)
                                  this.sUnit = dlbUnit.getSelection().toString() ;     ;
                             }      // end of if
                          /* Data Validation */
                             /* try block for numeric Exception */
                             try
                                 /* checking for any field left blank by the user */
                                  if(sFname.equals("") || sSname.equals("") ||  sAge.equals("")|| sExp.equals("") || sSkill.equals(""))
                                        /* set error flag to 1 in case of any field left blank */
                                        iErrFlag=1;
                                  } // end of if
                                  else
                                        /* converting Age and Experience fields (String) to integer */
                                         iAge= Integer.parseInt(sAge);
                                         iExp= Integer.parseInt(sExp);
                                       /* setting the boundaries on the value in Age Field */
                                         if(iAge<0)
                                             /* set error flag to 2 in case of age below 0 */
                                             iErrFlag=2;
                                         }// end of if
                                       /* setting the boundaries on the value in Experience field */
                                          else if(iExp<0 ||(iExp/12)>=iAge)
                                              /* set error flag to 3 in case of experience below 0 or exceeding the age in years */
                                              iErrFlag=3;
                                          }// end of else if
                                          /* In case of no error */
                                          else
                                             /* setting the bean variables */
                                             try
                                                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                                 Connection con = DriverManager.getConnection("jdbc:odbc:Test");
                                                 String query="insert into UserData values(?,?,?,?,?,?)";
                                                 PreparedStatement prestat=con.prepareStatement(query);
                                                 /* setting the values to be inserted into the user table */
                                                 prestat.setString(1,sFname);
                                                 prestat.setString(2,sSname);
                                                 prestat.setString(3,sAge);
                                                 prestat.setString(4,sExp);
                                                 prestat.setString(5,sSkill );
                                                 prestat.setString(6,sUnit);
                                                 prestat.executeUpdate() ;
                                                 prestat.close();
                                                 con.close();
                                                 myNameContainer.setSFname(sFname);
                                                 myNameContainer.setSLname(sSname);
                                                 myNameContainer.setSAge(sAge);
                                                 myNameContainer.setSExp(sExp);
                                                myNameContainer.setSSkill(sSkill);
                                                myNameContainer.setSUnit(sUnit);
                                             } // end of inner try block
                                              catch(Exception sqle)
                                                 myNameContainer.setErrMessage("Update failed ! Please try again." );
                                              } // end of catch corresponding to inner try
                                                           } // end of inner else
                                                      } //end of outer else
                                   } //end of outer try block
                                   catch(Exception e)
                                     /* setting flag to 4 in case of non-numeric age/experience values */
                                     iErrFlag = 4;
                                     /* Displaying error message corresponding to the value of error flag */
                                  switch(iErrFlag)
                                    /* Empty Field */
                                    case 1:myNameContainer.setErrMessage( "Please Fill all the fields");
                                    break;
                                    /* Invalid Value in the age field */
                                    case 2:myNameContainer.setErrMessage( "Enter a valid value in Age field.(Hint : Have you entered Age<0 ?");
                                    break;
                                    /* Invalid Value in the experience field */
                                    case 3:myNameContainer.setErrMessage( "Enter a valid value in Experience field.(Hint : Experince should not be negative or greater than your age in months)");
                                    break;
                                    /* Non-numeric value in the Age/ experience fields */
                                    case 4:myNameContainer.setErrMessage( "Please Enter Numeric Value for Age and Experience");
                                    break;
                                 } // end of switch-case block
              } //end of doProcessAfterInput()
         * Method          :           doProcessBeforeOutput()
         * Description      :                         
         * Input Parameters     :     None
         * Returns          :          None
                  public void doProcessBeforeOutput() throws PageException
                       /* Displays Form for new user creation by default */
                       this.setJspName("P_SAP_B_UserCreationForm.jsp");
                         /* In case of an error display an error message page */
                         if(iErrFlag!=0)
                              setJspName("ErrorPage.jsp");
                         } //end of if
                         /* Displays the user's information as entered in the SQL
                            database after its been uploaded by the user */
                         else if(iFlag==1)
                             setJspName("hello.jsp");      
                          } // end of else if
                  } // end of doProcessBeforeOutput()
              } // end of P_SAP_B_UserDynPage Class
         } // end of P_SAP_B_User class
    * End of File P_SAP_B_User.java
    2) Bean
    package com.sap.usercreation;
    import java.io.Serializable;
    public class P_SAP_B_CreateUser implements Serializable
         private String sFname;
         private String sLname;
         private String sUnit;
         private String sSkill;
         private String sExp;
         private String sAge;
         private String errMessage;
         * @return
         public String getSFname() {
              return sFname;
    * @return
    public String getSLname() {
         return sLname;
    * @param i
    * @param string
    public void setSFname(String string) {
         sFname = string;
    * @param string
    public void setSLname(String string) {
         sLname = string;
    * @return
    public String getSUnit() {
         return sUnit;
    * @param string
    public void setSUnit(String string) {
         sUnit = string;
    * @return
    public String getSSkill() {
         return sSkill;
    public void setSSkill(String string) {
         sSkill = string;
    * @return
    public String getSAge() {
         return sAge;
    * @return
    public String getSExp() {
         return sExp;
    * @param string
    public void setSAge(String string) {
         sAge = string;
    * @param string
    public void setSExp(String string) {
         sExp = string;
    * @return
    public String getErrMessage() {
         return errMessage;
    * @param string
    public void setErrMessage(String string) {
         errMessage = string;
    3) The Jsp file i have already posted.
    See if you copy this code and paste it wont work as i have not given you full code ,But yes this gives you an overview of how things can be done .
    Thanx
    Pankaj

  • How to break up a huge XML file and generate serialized JSP pages

    I have a huge xml file, with about 100 <item> nodes.
    I want to process this xml file with pagination and generate jsp pages.
    For example:
    Display items from 0 to 9 on page 1 page1.jsp , 10 to 19 on page2.jsp, and so on...
    Is it possible to generate JSP pages like this?
    I have heard of Velocity but dont know if it will be the right technology for this kind of a job.

    Thank you for your reply, I looked at the display tag library and it looks pretty neat with a lot of features, I could definitely use it in a different situation.
    The xml file size is about 1.35 MB, and the size is unpredictable it could shrink or grow periodically depending on the number of items available.
    I was hoping to create a documentation style (static pages) of the xml feed instead of having 1 jsp with dynamic pages
    I was looking at Anakia : http://jakarta.apache.org/velocity/docs/anakia.html , may be it has features that enable me to create static pages but not very sure.
    I think for now, I will transform the xml with an xsl file and pass the page numbers as input parameters to the xsl file
    null

  • How to create a xml file from the jsp page?

    I'm a beginner of the develop xml,my question like this,
    there has a jsp page,some parameters in it,I wanna get the parameters and create a xml file,so,what parser method should I use?
    And how to create a new xml file,when the file haven't exist at first?
    pls give some code,thanks.

    a ggod link for u http://www.theserverside.com/resources/article.jsp?l=JSP-XML2

  • Using an XML document in several JSP Pages

    I am using a certain XML document in several different JSP pages (I have several JSP pages in which I need to get data from and save data to the document)
    I'd thought about using it as a bean so that I don't have to reopen it in every page, but I can't since the "Docuemnt" object is actually an interface.
    This is the code I'm using to open the document:
    final String fileName= "./doc/config.xml";
    int listLength, listLengthAuthors;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    File xmlFile = new File(fileName);
    xmlDoc = builder.parse(xmlFile);
    Any ideas?

    I'd thought about using it as a bean so that I don't have to reopen it in every page, but I can't since the "Docuemnt" object is actually an interface.Use it as a bean. The Document "class" is an interface, but the object you get from DocumentBuilder is an object just like any other object, and there are no restrictions on how you can use it. Try it.

  • Submitting a XML Publisher Report from JSP page

    Hello,
    We have need to submit a XML Publisher report from Quoting/iStore module in Oracle Ebusiness. The out put should be viewable in PDF format and user should be able to print. can anyone pls help on how this can be achieved.
    TIA

    Really appreciate your response. Can you pls give little more details.
    1] Are there any standard API's which I can use to submit XML publisher report from the JSP pages
    2]Is there any sample code snippet for any of the options that I can refer to..or pls let me know the API's, I will check on them
    Appreciate any help

  • How to show an xml content in a Jsp page?

    I use <jsp:include page=".....xml" /> tag in a jsp file to include an xml file. When this jsp page is open, only the text content in the xml file shows up with plain text. I want this xml file shows up like in IE (with xml format). Does anyone know how to do it? Thanks.
    northcloud

    Thank you, BalusC & evnafets. Someone told me to use <c:import> to load the XML file into a scoped variable, and then use <c:out> to display it. The <c:out> will automatically convert the markup to HTML entities. I tried it, it works. It shows the content in the xml file as plain text (a long string). Any one give me some suggestion to make it looking better, for example, show each element in seperated lines. Thanks.

  • Generating XML on Submit of JSP Page

    Dear all,
    We need to code JSP pages which will generate the XML Request document dynamically after user submits the form.
    Can anybody tell, how to go about doing this?
    Thanks & Regards
    Seema

    the general idea is to get the data after the submit and call a java class, that you have to code, wich will generate an xml doc with the submitted data.
    for more details about how to code an xml java class take a glance at this
    http://forum.java.sun.com/thread.jsp?forum=34&thread=416365
    hope this will help!

  • Java compilation and running within jsp page

    hi,
    i need of a jsp page that has a textarea in which the java coding are entered and this coding is compiled and executed. The execution result is printed.
    Please guide me.

    I don't think you can invoke java compiler or run time environment at client side (browser). Even if you use applet, i think you will not be able to do it at client side. Moreover, though java virtual machine will be available in your target user's browser, but you should not expect a java compiler in users machine.
    I have seen exam sites where they have added java code compilation and execution ability. To achieve this you can do:
    1. In your JSP page use text area where user can edit java code.
    2. Provide two buttons - 'Compile' and 'Run'.
    3. On click of 'Compile' send the code to server side. In server machine create a file in a temporary location in disk and save the code content received from client.
    4. Invoke 'javac' command (as a separate process) to compile the java class created in step 3. This process will give you error/output back which you can send back to user.
    5. In case of 'Run' you must first invoke above mentioned 'Compile' service and then another service ('Run') to actually run you java class. You can build 'Run' service in similar way.
    Here you challenge would be managing multiple client requests (to compile and run java class) at the same time.
    Code to compile and run java classes:
    import java.io.*;
    * A class to compile and run java classes.
    * @author Mrityunjoy Saha
    public class JavaProcessor{
         public static void main(String[] args){
              // Option 1 to compile and option 2 to run.
              int option=1;
              if(args.length > 0){
                   option=Integer.parseInt(args[0]);
              JavaProcessor p=new JavaProcessor();
              if(option==1){
                   p.compile();
              } else {
                   p.run();
         public void run(){
              String file="FoodTest";
              String directory="C:/Users/mrityunjoy_saha/Documents/Test";     
              executeCommand("java", directory, file);
         public void compile(){
              String file="FoodTest.java";
              String directory="C:/Users/mrityunjoy_saha/Documents/Test";     
              executeCommand("javac", directory, file);
         public void executeCommand(String command, String directory, String file){
              try{
                   String[] envp=null;
                   // Make sure that you have done Java setup in your machine.
                   // To test this try invoking javac command in command prompt.
                   Process p=Runtime.getRuntime().exec(command+" "+file,envp,new File(directory));
                   BufferedReader errorStream=new BufferedReader(new InputStreamReader(p.getErrorStream()));
                   String readData="";
                   while((readData=errorStream.readLine())!=null){
                        System.out.println(readData);
                   BufferedReader outStream=new BufferedReader(new InputStreamReader(p.getInputStream()));
                   readData="";
                   while((readData=outStream.readLine())!=null){
                        System.out.println(readData);
              catch(IOException ioe){
                   ioe.printStackTrace();
    }Thanks,
    Mrityunjoy

  • Parsing XML and pulling out results rows only

    All,
    I need a bit of direction here, hopefully someone can help.
    Here is the situation..
    I have a Web Template that has the XML dataprovider only. Meaning, when I execute it, I get a blank screen because I am not using any other item. This is expected.
    The query works as designed and the XML data in the source of the web page is correct.
    Now, I want to be able to read (loop thru the XML data) and display the data in an HTML table for display to the end user. (Actually, I would like to only keep the "REsults Rows" from the XML data)
    Does anyone have any javascript/XSL/etc that takes the data from a web template, via the XML dataprovider function, and is able to process the data (XML data) and display as an HTML table on the same page?
    I am having a hard time finding any information on reading an XML dataset from the WAD and displaying it with any sort of success.
    I found lots of weblogs and threads about some similiar functionality, but it wasn't exactly what I was looking for.
    Here are some of the links I found..
    Re: XML Data Provider - Information
    I also found other threads from here, but none of them was exactly what I was looking for...(They were along the same lines as the first link!)
    I hope someone can help me out. Due points and my ever gratitude to whomever can help me on this one!
    Cheers!
    /smw

    1. Learn basic web service interfacing. The type of data is irrelevant.
    2. Learn how to parse XML.
    3. Learn how jdbc works.
    4. Learn how the protocol of your actual hosting company works.
    5. Put the above steps together to create your app.
    Steps 1, 2 and 3 are independent from each other.

  • XML view of the JSP Page

    Hi,
    i've got a little problem.
    When i put a control in a jsp page, and remove it, or anything else, the "source tab" always show me the same XML code, althought i'm saving all my documents via ctr+shift+s
    What's wrong ?? is there a way to "regenerate" a clean xml file ?
    Thanks.

    Hi,
    Adding a control and then deleting it is working for me. The source tab is in sync with the design view and it does not show the code for the removed component.
    Could you please tell us how you removed the control?
    To remove a control you can go to the application outline window, right click on the component to be removed and choose delete. This should work fine.
    Cheers
    Giri :-)
    Creator Team

  • Parsing XML and Storing values in instance variable

    hi,
    i'm new to XML.
    here i'm trying to parse an XML and store their element data to the instance variable.
    in my main method i'm tried to print the instance variable. but it shows "" (ie it print nothing ).
    i know the reason, its becas of the the endElement() event generated and it invokes the characters() and assigns "" to the instance variable.
    my main perspective is to store the element data in instance variable.
    thanks in advance.
    praks
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    public class mysax extends DefaultHandler
         String ctelement;
         CharArrayWriter contents;
         String vname1,vrcbreg1,vaddress1,vcountry1,vtelephone1,vfax1;
         String vname,vrcbreg,vaddress,vcountry,vtelephone,vfax;
         public mysax()
              vname1 = null;
              vrcbreg1 = null;
              vaddress1 = null;
              vcountry1 = null;
              vtelephone1 = null;
              vfax1 = null;
              contents= new CharArrayWriter();
         public void doparse(String url) throws Exception
              SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    ParserAdapter pa = new ParserAdapter(sp.getParser());
    pa.setContentHandler(this);
    pa.parse(url);          
         public void startElement(String namespace,String localName,String qName,Attributes atts)
              ctelement = localName;     
         public void endElement(String uri,String localName,String qName) throws SAXException
         public void characters(char[] ch,int start, int length) throws SAXException
              try
                   if(ctelement.equals("name"))
                        vname = new String (ch,start,length);
                        System.out.println("The method "+vname1);
              }catch (Exception e)
                   System.out.println("The exception "+e);
         public static void main(String args[])
              try
              mysax ms = new mysax();
              ms.doparse(args[0]);
              System.out.println("the contents name "+ms.vname1);
              catch(Exception e)
                   System.out.println("this is exception at main" +e);
    my XML looks like
    <coyprofile_result>
    <company>     
    <name>abcTech</name>
    <rcbreg>123456789</rcbreg>
    <address>Singapore</address>
    <country>sg</country>
    <telephone>123456</telephone>
    <fax>123155</fax>
    </company>
    </coyprofile_result>

    I believe that the problem has to do with the value you assign to ctelement. You are assigning the value of localName to ctElement, however for the element: <name>...</name> the localname is empty string i.e. "", but qName equals "name". Because you are assigning empty string to ctElement, when you do the comparison in characters of ctElement to "name" it will always be false. So in startElement change it to ctElement = qName; Try it and see if it works. I have produced similar programs and it works for me.
    Hope this helps.

  • Session Login and Logout in jsp page

    hi
    i am developing jsp page
    i completed except logout.jsp page
    my login page is in Jsp format and then business Logic in servlet and then get method & set method in bean.java
    i have login and then it sucess page there i have singout button
    if i sign out it should go to login page
    how to do
    how to make session invalidate
    how to get session id
    i have one more doubt i should check session invalidate each jsp page
    regarding session login and logout in jsp
    if anybody knows please give me a piece of code regarding login and logout
    Regards
    Akshatha

    This is part of your filter class now you need login.jsp page
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="Stylesheet" type="text/css" href="/PAS/css/site.css"/>
        <title>Automation System | Login Page</title>
    </head>
    <body>
    <div align="center">
        <h1>Photint Automation System</h1>
    </div>
    <br/><br/><br/>
    <center>
        <table border="1" cellpadding="0" cellspacing="0" width="40%" bgcolor="FFFFFFFF">
            <thead>
                <tr>
                    <th align="left" height="30"> <h3>    Login</h3></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <div align="center">
                            <form name="LOGIN" action="/PAS/LoginServlet" method="POST">
                                <table border="0">
                                    <tbody>
                                        <tr>
                                            <td height="15"></td>
                                            <td height="15"></td>
                                            <td height="15"></td>
                                            <td height="15"></td>
                                        </tr>
                                        <tr>
                                            <td height="30"></td>
                                            <td align="right" height="30">User Name : </td>
                                            <td align="left"  height="30"><input type="text" name="USERNAME" value="" size="35"  /></td>
                                            <td height="30"></td>
                                        </tr>
                                        <tr>
                                            <td height="30"></td>
                                            <td align="right" height="30">Password : </td>
                                            <td align="left"  height="30"><input type="password" name="PASSWORD" value="" size="35"  /></td>
                                            <td height="30"></td>
                                        </tr>
                                        <tr>
                                            <td height="50"></td>
                                            <td height="50"></td>
                                            <td align="center" height="50"><input type="submit" value="Login" name="Login" />  <input type="reset" value="Reset" name="Reset" /></td>
                                            <td height="50"></td>
                                        </tr>
                                    </tbody>
                                </table>
                            </form>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </center>
    <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
    <br/><br/><br/>
    <center>Copyright &copy; 2009 Photint FZ LLC</center>
    <center>Powered by Ali Jamali</center>
    <center>Version : 1.0</center>
    </body>
    </html>And you need loginServlet.java
    package com.ali.util.filter;
    import com.ali.entity.user.UserEntity;
    import com.ali.util.HibernateUtil;
    import java.io.IOException;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    public class LoginServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            String username = request.getParameter("USERNAME");
            String password = request.getParameter("PASSWORD");
            if (username == null || username.length() == 0) {
                System.err.println(" Username textfeild is empty ..... !");
                RequestDispatcher dispatcher = request.getRequestDispatcher("Pages/user/LogIn.jsp");
                dispatcher.forward(request, response);
                return;
            if (UserRegistry.isUserLoggedIn(username)) {
                System.out.printf("User [%s] is already logged in. \n", username);
                RequestDispatcher dispatcher = request.getRequestDispatcher("Pages/user/LogIn.jsp");
                dispatcher.forward(request, response);
                return;
            UserEntity user = null;
            try {
                user = (UserEntity) HibernateUtil.load(UserEntity.class, username);
                if (user == null || !user.getPassword().equals(password)) {
                    RequestDispatcher dispatcher = request.getRequestDispatcher("Pages/user/LogIn.jsp");
                    dispatcher.forward(request, response);
                    System.err.println(" Password or username is not valid ..... !");
                    return;
            } catch (Exception e) {
                e.printStackTrace();
                RequestDispatcher dispatcher = request.getRequestDispatcher("Pages/user/LogIn.jsp");
                dispatcher.forward(request, response);
                return;
            HttpSession session = request.getSession();
            System.err.println(request.getRemoteAddr());
            session.setAttribute("username", user.getFirstName());
            session.setAttribute("userType", user.isAdmin());
            UserRegistry.logInUser(username);
            response.sendRedirect("/PAS/index.jsp");
    }finally is you need to just one user can be online at time or need to know how many user & who is online you should at this class also
    package com.ali.util.filter;
    import java.util.ArrayList;
    import java.util.List;
    public class UserRegistry {
        private static final List loggedInUsers = new ArrayList();
        public static void logInUser(String username) {
            loggedInUsers.add(username);
        public static void logoutUser(String username) {
            if (isUserLoggedIn(username)) {
                loggedInUsers.remove(username);
        public static boolean isUserLoggedIn(String username) {
            return loggedInUsers.contains(username);
    }If you have any more Q. or any comment , Most welcome
    Thanks
    Ali Jamali

  • Read a property file value and display in jsp page

    I need a solution for the below mentioned scenario,
    I want to read a value from the property file in JSP page.
    For Example, Let us have a property file called A.properties, in the file, we have a value, username = Sam.
    I want to bring this value in the jsp page.
    Please assist in this issue.
    thanks in advance.

    If you are using struts, then you have to first load the taglib like
    <%@ taglib uri="/WEB-INF/strutsresources/struts-bean.tld" prefix="bean" %>and then access the particular property like
    <bean:message key="welcome"/>Also, you have to define <message-resources> in struts-config. Though I am not into struts for year now, So, please confirm the code.

Maybe you are looking for

  • Can I restore just One Application through time machine? (vs. Migration)

    Hi. I've reformatted my Mac Instead of Migration Assistant I want to restore just ONE application (Microsoft Office) 1. I've plugged in my Time Machine 2. Time Machine is Not Configured 3. I Browse Other Time Machine Disks 4. I Use Selected Disk 5. I

  • Creating business components programmatically

    Hello, I've been working with ADF 11g and JDeveloper for some time, and I've found very useful to be able to create programmatically view objects and child application modules without having to declare them "statically" in the application modules whe

  • Is it possible to show OOB document call out menu or ECB menu in Content Search web part?

    Hi All, We have requirement like we need to show the Call Out option in custom display template of Content Search webpart. Is it possible to do it? We are showing the documents from current site in Content Search web part. Now customer want to have C

  • Dealer Commissions interface file

    Hi, I got a requirement like Process the input interface file from Dealer Commissions to enter GL info into SAP by formatting BDC records which are to be used by transaction F-02 in a batch mode. can any ony one explain me what is the requirement act

  • How to Load data for Inventory Organizations

    Hi All, I have flat file containing data for following fields, Organization Code, Name, From(Date), Location,Org Classification ,Primary Ledger, Legal Entity, Operating Unit ,Item Master Org,     Material Account,     Outside Processing,     Material