XML SERVLET Communicaiton.. ?

Hi All,
Anybody please tell me how to communicate xml and servlet each other.
I have to make a program in which servlet will call xml attribute and print the xml attribute .
Please help.
Please reply with coding ...
Thanks
Harish Pathak

Double Post: http://forum.java.sun.com/thread.jspa?threadID=707034
Your question is extremely unclear, please clarify what you want to achieve. Read How To Ask Questions The Smart Way if you don't know how to do that.

Similar Messages

  • 'Workflow's EVENT_DATA TYPE Using AQ XML Servlet

    Is there a way to put xml into the event_data subtype of the WF_EVENT_T type without escaping it as a CDATA section?
    Currently, I have to escape the content of the EVENT_DATA element, otherwise it thinks it is part of the WF_EVENT_T type if the contents itself is XML.
    Note that workflow's EVENT_DATA Subtype is CLOB. From PL/SQL I can put XML into it with no problem. But from the AQ XML servlet, I had to escape the XML before it could take it. Escaping the XML is not a good option because all brackets (<, /, >, ...) are escaped.
    Thanks,
    Yves

    I have already walked through the sample. Here is my xml document when I am posting it with the CDATA section wrapping the EVENT_DATA Element:
    <Envelope xmlns= "http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
    <AQXmlPublish xmlns = "http://ns.oracle.com/AQ/schemas/access">
    <producer_options>
    <destination>OWF_MGR.WF_IN</destination>
    </producer_options>
    <message_set>
    <message_count>1</message_count>     
    <message>
    <message_number>1</message_number>
    <message_header>
         <delay>0</delay>
         <sender_id>
         <agent_name>john</agent_name>
         <protocol>0</protocol>
         </sender_id>
    </message_header>
    <message_payload>     
    <WF_EVENT_T>
    <PRIORITY>0</PRIORITY>
    <EVENT_NAME>oracle.apps.wf.event.vn.test.demo</EVENT_NAME>
    <EVENT_KEY>yves40</EVENT_KEY>
    <TO_AGENT>
    <NAME>WF_IN</NAME>
    <SYSTEM>VNDBACCT.FANNIEMAE.COM</SYSTEM>
    </TO_AGENT>
    <EVENT_DATA><![CDATA[
    <vnml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://fanniemae.com/vnml/schema?version=1.94">
    <project>
    <vndb date="2002-05-06" name="Book of Business" status="success" id="45"/>
    <market abc="xxx">
    <vndb action="select" id="50"/>
    </market>
    </project>
    </vnml>]]>
    </EVENT_DATA>
    </WF_EVENT_T>
    </message_payload>
    </message>
    </message_set>
    <AQXmlCommit>
    </AQXmlCommit>
    </AQXmlPublish>
    </Body>
    </Envelope>

  • Need HELP!! Where I have to place an web.xml(servlet) file on server

    I'm using E-business suite for oracle HR version 11.
    On localhost i have developed an servlet file with using web.xml. On web.xml i have customized the file that can load a class for my servlet.But when I deploy on the server i had a cnfused wher do i have to place web.xml and my servlet.
    I have made an servlet file for my custom. Where do I have to place an xml(servlet) file on server?
    Would you give me know forsolving my problem.Please give me know,I really appreciated if you want to give some solution.
    Regards,
    Dany Fauzi

    Copy web.xml to WEB-INF directory of the web application.

  • Who can help solve this XML/Servlet mystery?

    Hi,
    I'm developing a servlet that accepts an HTTP request, contacts a database, processes the request and return an XML document back to the browser. The XML document returned is dependent on which selection a user makes.
    The problem is that on first request, say user selects "choice one", the correct XML document is returned. However, when the browser's back button is used to go back and make the same choice as previous(ie "choice one"), Explorer 4.5 displays an empty page while netscape 4.5 return a document contains no data error.
    I used oracle xmlclassgenerator to generate the classes that create the XML document to be returned. The problem certainly lies in the method of my servlet that uses these classes to generate the XML document because when I replace the whole method with println statement every thing works fine(but of course without the XML document).
    The content of the method is as follows.
    ACCOUNT acc = new ACCOUNT(id);
    //Create a child and add child to root node
    NUM_OF_RESIDENTS nr = new NUM_OF_RESIDENTS(num);
    acc.addNode(nr);
    //Create another child and add to root node
    FIXED_COST fc = new FIXED_COST();
    ELECTRICITY el = new ELECTRICITY(elec);
    GAS g = new GAS(gas);
    WASH_MACHINE wm = new WASH_MACHINE(wash);
    WATER wat = new WATER(water);
    OTHER oth = new OTHER(other);
    fc.addNode(el);
    fc.addNode(g);
    fc.addNode(wm);
    fc.addNode(wat);
    fc.addNode(oth);
    //finally add to root node
    acc.addNode(fc);
    //Create another child
    TELEPHONE tl = new TELEPHONE();
    SUBSCRIPTION sub = new SUBSCRIPTION(tel);
    COST_PER_TICK cpt = new COST_PER_TICK(tick);
    tl.addNode(sub);
    tl.addNode(cpt);
    acc.addNode(tl);
    //Create another child
    // PREVIOUS_ACCOUNT pacc = new PREVIOUS_ACCOUNT();
    for(int i=0; i<previous_details.size(); i++){
    //Create another child
    PREVIOUS_ACCOUNT pacc = new PREVIOUS_ACCOUNT();
    PreviousDetails pd = (PreviousDetails)previous_details.elementAt(i);
    String name = pd.getName();
    String credit = pd.getCredit();
    String debit = pd.getDebit();
    NAME n = new NAME(name);
    LAST_CREDIT lc = new LAST_CREDIT(credit);
    LAST_DEBIT ld = new LAST_DEBIT(debit);
    pacc.addNode(n);
    pacc.addNode(lc);
    pacc.addNode(ld);
    acc.addNode(pacc);
    for(int i=0; i<acc_dates.size(); i++){
    String str = (String)acc_dates.elementAt(i);
    ACCOUNT_DATE ad = new ACCOUNT_DATE(str);
    acc.addNode(ad);
    acc.validateContent();
    ByteArrayOutputStream out1 = new ByteArrayOutputStream(1024);
    acc.print(out1);
    res.setContentType("text/plain");
    ServletOutputStream os = res.getOutputStream();
    PrintWriter out = new PrintWriter(os);
    out.println(out1.toString());
    out.close();
    catch(Exception e){}
    Am I doing somthing wrong here?
    Thanks.
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Steven Muench ([email protected]):
    If you paste your code that's in the servlet into a file with a static main() method, and if you wrap the code with a for loop in Java that makes it execute 3 times in a row, does it work properly each of the the 3 times in this scenario?<HR></BLOCKQUOTE>
    I have done as you requested. For your convenience I have pasted both the code and its output below.
    import oracle.xml.classgen.*;
    import oracle.xml.parser.*;
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    import java.math.*;
    public class CreateTest{
    static String id = "10212";
    public static void main (String args[]){
    for(int i=0; i<3; i++){
    System.out.println("Request started!");
    testLoop();
    static void testLoop(){
    try{
    System.out.println("Start DB contact");
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn =
    DriverManager.getConnection ("jdbc:oracle:thin:@my_ip:sid","username", "passwd");
    ResultSet rset;
    Vector acc_dates = new Vector();
    Vector previous_details = new Vector();
    String elec = null;
    String gas = null;
    String wash = null;
    String water = null;
    String other = null;
    String tel = null;
    String tick = null;
    String num = null;
    Statement stmt = conn.createStatement();
    rset = stmt.executeQuery("select NUM_OF_RESIDENTS from MEMBER WHERE ID="+id);
    while(rset.next()){
    num = String.valueOf(rset.getInt(1));
    rset = stmt.executeQuery("select ELECTRICITY,GAS,WASH_MACHINE,WATER,OTHER from FIXED_COST where ID="+id);
    while(rset.next()){
    elec = String.valueOf(rset.getFloat(1));
    gas = String.valueOf(rset.getFloat(2));
    wash = String.valueOf(rset.getFloat(3));
    water = String.valueOf(rset.getFloat(4));
    other = String.valueOf(rset.getFloat(5));
    rset = stmt.executeQuery("select SUBSCRIPTION,COST_PER_TICK from TELEPHONE WHERE id="+id);
    while(rset.next()){
    tel = String.valueOf(rset.getFloat(1));
    tick = String.valueOf(rset.getFloat(2));
    rset = stmt.executeQuery("select NICK_NAME, CREDIT, DEBIT from PREVIOUS_ACCOUNT WHERE LAST_ACCOUNT='yes' AND id="+id);
    while(rset.next()){
    String name = rset.getString(1);
    String credit = String.valueOf(rset.getFloat(2));
    String debit = String.valueOf(rset.getFloat(3));
    PreviousDetails pd = new PreviousDetails(name,credit,debit);
    previous_details.addElement(pd);
    rset = stmt.executeQuery("select ACCOUNT_DATE from ACCOUNT_RESULT WHERE ID="+id);
    while(rset.next()){
    acc_dates.addElement(rset.getString(1));
    rset.close();
    stmt.close();
    conn.close();
    System.out.println("End DB contact");
    generateXMLDocument(num,elec,gas,wash,water,other,tel,tick,previous_details,acc_dates);
    catch(Exception e){e.printStackTrace();}
    public static void generateXMLDocument(String num, String elec, String gas, String wash, String water, String other, String tel, String tick, Vector previous_details, Vector acc_dates){
    try{
    //Create the document root node
    ACCOUNT acc = new ACCOUNT(id);
    //Create a child and add child to root node
    NUM_OF_RESIDENTS nr = new NUM_OF_RESIDENTS(num);
    acc.addNode(nr);
    //Create another child and add to root node
    FIXED_COST fc = new FIXED_COST();
    ELECTRICITY el = new ELECTRICITY(elec);
    GAS g = new GAS(gas);
    WASH_MACHINE wm = new WASH_MACHINE(wash);
    WATER wat = new WATER(water);
    OTHER oth = new OTHER(other);
    fc.addNode(el);
    fc.addNode(g);
    fc.addNode(wm);
    fc.addNode(wat);
    fc.addNode(oth);
    //finally add to root node
    acc.addNode(fc);
    //Create another child
    TELEPHONE tl = new TELEPHONE();
    SUBSCRIPTION sub = new SUBSCRIPTION(tel);
    COST_PER_TICK cpt = new COST_PER_TICK(tick);
    tl.addNode(sub);
    tl.addNode(cpt);
    acc.addNode(tl);
    //Create another child
    // PREVIOUS_ACCOUNT pacc = new PREVIOUS_ACCOUNT();
    for(int i=0; i<previous_details.size(); i++){
    //Create another child
    PREVIOUS_ACCOUNT pacc = new PREVIOUS_ACCOUNT();
    PreviousDetails pd = (Previou sDetails)previous_details.elementAt(i);
    String name = pd.getName();
    String credit = pd.getCredit();
    String debit = pd.getDebit();
    NAME n = new NAME(name);
    LAST_CREDIT lc = new LAST_CREDIT(credit);
    LAST_DEBIT ld = new LAST_DEBIT(debit);
    pacc.addNode(n);
    pacc.addNode(lc);
    pacc.addNode(ld);
    acc.addNode(pacc);
    for(int i=0; i<acc_dates.size(); i++){
    String str = (String)acc_dates.elementAt(i);
    ACCOUNT_DATE ad = new ACCOUNT_DATE(str);
    acc.addNode(ad);
    acc.validateContent();
    ByteArrayOutputStream out1 = new ByteArrayOutputStream(1024);
    acc.print(out1);
    System.out.println("The result is:");
    System.out.println(out1.toString());
    catch(Exception e){}
    The output is:
    Request started!
    Start DB contact
    End DB contact
    The result is:
    <!DOCTYPE ACCOUNT SYSTEM "file:/home/httpd/html/tydex/dtd/ACCOUNT_dtd.txt">
    <ACCOUNT ID="10212">
    <NUM_OF_RESIDENTS>3</NUM_OF_RESIDENTS>
    <FIXED_COST>
    <ELECTRICITY>0.0</ELECTRICITY>
    <GAS>0.0</GAS>
    <WASH_MACHINE>0.0</WASH_MACHINE>
    <WATER>0.0</WATER>
    <OTHER>0.0</OTHER>
    </FIXED_COST>
    <TELEPHONE>
    <SUBSCRIPTION>0.0</SUBSCRIPTION>
    <COST_PER_TICK>0.0</COST_PER_TICK>
    </TELEPHONE>
    <PREVIOUS_ACCOUNT>
    <NAME>dsffd</NAME>
    <LAST_CREDIT>0.0</LAST_CREDIT>
    <LAST_DEBIT>0.0</LAST_DEBIT>
    </PREVIOUS_ACCOUNT>
    <PREVIOUS_ACCOUNT>
    <NAME>dsfd</NAME>
    <LAST_CREDIT>0.0</LAST_CREDIT>
    <LAST_DEBIT>0.0</LAST_DEBIT>
    </PREVIOUS_ACCOUNT>
    <PREVIOUS_ACCOUNT>
    <NAME>dsfdfs</NAME>
    <LAST_CREDIT>0.0</LAST_CREDIT>
    <LAST_DEBIT>0.0</LAST_DEBIT>
    </PREVIOUS_ACCOUNT>
    </ACCOUNT>
    Request started!
    Start DB contact
    End DB contact
    Request started!
    Start DB contact
    End DB contact
    Thanks.
    null

  • Web service / XML-RPC:  SMTP inbound to OC4J/BC4J XML servlet bridge??

    A new business problem just landed on my desk for a possible solution.
    One way XML documents coming in from a Novel mail server doing SMTP forward to something
    in the OC4J, BC4J, side to receive and parse the XML.
    It would be great of course if the JDev / BC4J / OC4J web services tools had a SMTP service
    that would route inbound SMTP messages at email address to a particular Servlet.post().
    Any other ideas??
    Thanks much,
    curt

    For others, here is a start of a response to Curtis's message talking about the BC4J Web services features combined with the BC4J readXML and writeXML capabilities:
    Re: Can we find when was a table dropped?
    Not sure if other folks have a solution to dealing with the SMTP part - a snippet of code that works with readXML and writeXML methods of BC4J, for example.
    Mike.

  • Web Service/XML-RPC: SMTP inbound to BC4J Xml Servlet bridge idea??

    A new business problem just landed on my desk for a possible solution.
    One way XML documents coming in from a Novel mail server doing SMTP forward to something
    in the OC4J, BC4J, side to receive and parse the XML.
    It would be great of course if the JDev / OC4J web services tools had a SMTP service
    that would route inbound SMTP messages at email address to a particular Servlet.post().
    Any other ideas??
    Thanks much,
    curt

    For others, here is a start of a response to Curtis's message talking about the BC4J Web services features combined with the BC4J readXML and writeXML capabilities:
    Re: Can we find when was a table dropped?
    Not sure if other folks have a solution to dealing with the SMTP part - a snippet of code that works with readXML and writeXML methods of BC4J, for example.
    Mike.

  • Web.xml servlet redirection question

    Hi everyone;
    As you know web.xml file allows you to enter something like this
         <servlet-mapping>
              <servlet-name>application1</servlet-name>
              <url-pattern>/application1</url-pattern>
         </servlet-mapping>
    so you can find your application.
    As you know it is case sensitive so if a user enters /Application1 it wouldn't be found. I was wondering if i could put a node in there that would redirect requests from Application1 to application.
    Any ideas ?
    Stev

    oh i wasn't aware that i could put multiple nodes in there like this
    <servlet-mapping>
    <servlet-name>application1</servlet-name>
    <url-pattern>/application1</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>application1</servlet-name>
    <url-pattern>/Application1</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>application1</servlet-name>
    <url-pattern>/APplication1</url-pattern>
    </servlet-mapping>
    is there a way to simply make this case insensitive and all requests get translated to the lowercase versioN?
    Stev

  • XML,servlets and websphere?

    I am working on a project that is using websphere 3.5 as the application server, from a login page I call a servlet (SiteController) what I want to do is read in system specific values (such as jsp file address, database connectivity info, etc) from an XML file. Can anyone tell me what I should be doing to achieve this, please!!!!!

    There are a number of options;
    1. Use a DOM parser e.g. Xerces (http://xml.apache.org/xerces2-j/index.html) and figure out how to traverse to the info you kneed.
    2. Use Castor XML (http://castor.exolab.org/) to build a set of Java classes (need a schema for your config file) which are much easier to manipulate in java. Though this requires you to re-build the classes if the schema changes. You still need a parser - Castor by default requires Xerces.
    3. Event better might be to use Struts (http://jakarta.apache.org/struts/index.html) which has its own config file which supports jsp/JDBC connections etc, It also has a 'SiteController' servlet called ActionServlet which acts as the control point for the whole application.
    I'm currently using a mixture of 2 & 3 for a WAS4 prototype.
    There are white papers and tutorials on 2 & 3 on the IBM web site (Developer Works).
    http://www-106.ibm.com/developerworks/library/x-bindcastor/index.html
    http://www-106.ibm.com/developerworks/library/j-strutstiles.html
    http://www-106.ibm.com/developerworks/library/j-struts/index.html
    amongst others.
    HH

  • Web.xml & Servlet

              Hello,
              If i put my servelt class file as per directory provided by WLS.(i.e
              web-inf/... . ) Then do i need to add it into wex.xml file ?
              Thanks
              Jigar
              

              Hello,
              If i put my servelt class file as per directory provided by WLS.(i.e
              web-inf/... . ) Then do i need to add it into wex.xml file ?
              Thanks
              Jigar
              

  • Java XML servlet

    hii all
    i am querying an XMLobject in the servlet from the database.
    now i want to send the array of this XMLObject to a JSP page and display the attributes.
    also please note that it is not needed to display an XMLFile , insted i want to show array of XMLObject , each object in a single row in a tabular format.
    please help ....
    thanks

    hii all
    i am querying an XMLobject in the servlet from the database.
    now i want to send the array of this XMLObject to a JSP page and display the attributes.
    also please note that it is not needed to display an XMLFile , insted i want to show array of XMLObject , each object in a single row in a tabular format.
    please help ....
    thanks

  • XML Servlet

    Can the servlet connect to any DB that has JDBC support.
    null

    Hi Jay,
    Currently the XSQL servlet is hardcoded the connection to use
    OracleConnection class. But we are in the process of testing a
    new version which would connect to any database. Will keep you
    posted.
    Thx
    Murali
    Jay (guest) wrote:
    : Can the servlet connect to any DB that has JDBC support.
    null

  • Adding servlet entry in web.xml of j2ee engine

    Hi ,
    I want a servlet to be loaded on startup of the j2ee engine SAP WAS which is basically flex based (MessageBrokerServlet). 
    The init param for the servlet is not accessible or cannot be initialized in init method of the servlet using the servletconfig object.
    This is when the servlet is used as a portal component of type servlet.
    So as to load the servlet and the servlet being able to access the init param i would be changing the web.xml of the sap j2ee engine (NW CE 7.1). are there any other effects of the same or is it fine if i just add this param in the web.xml
        <servlet>
            <servlet-name>MessageBrokerServlet</servlet-name>
            <display-name>MessageBrokerServlet</display-name>
            <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
            <init-param>
                <param-name>services.configuration.file</param-name>
                <param-value>/WEB-INF/flex/services-config.xml</param-value>
           </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>

    Hi ,
    Vivek in case my servlet is part of the Portal Application as PortalComponent how do i define init parameters  that can be accessed in the servlet.
    The config file would be accessed in the init method of the servlet how do i do that when the servlet is added as PortalComponent in PortalApplication. The servlet config file needs to accessed in t he init method.
    The load on startup thing would be taken care of by setting parameter startup = true of application properties.
    Regards
    Srikumar V

  • Web.xml configuration for initial servlet load

    Hi all,
    I have heard of entering some tag into web.xml file (deployement descriptor) if we need some servlets to be loaded wheneve the app server starts or restarts. can some body help me regarding what to write in web.xml.
    thanks in advance

    I am having some problems with the same issue although specifying the load-on-startup param is not working for.
    Here is snipet of the web.xml:
    <servlet id="Servlet_1206024889339">
    <servlet-name>ContentServer</servlet-name>
    <servlet-class>COM.FutureTense.Servlet.SContentServer</servlet-class>
    <init-param id="InitParam_1206024988781">
    <param-name>inipath</param-name>
    <param-value>/data/WebSphere/ContentServer</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    This however doesn't init the contentServer servlet. Is there anythign else i need to check? I am using websphere5-1.
    I saw somewhere you might have to specify a loadonstartup=true? Where is this set?
    I know the app is reading the right web.xml because i put in a bad value and saw the error being outputted in the startup log.
    There are some servlets being initialised on startup but not the ones I want. These servlets don't seem to be in the web.xml.
    [10/10/08 11:53:30:265 IST] 1e06de8 WebContainer A SRVE0169I: Loading Web Module: cs.war.
    [10/10/08 11:53:33:330 IST] 1e06de8 WebGroup I SRVE0180I: [cs.war] [servlet] [Servlet.LOG]: JSP 1.2 Processor: init
    [10/10/08 11:53:34:098 IST] 1e06de8 WebGroup I SRVE0180I: [cs.war] [servlet] [Servlet.LOG]: SimpleFileServlet: init
    [10/10/08 11:53:34:117 IST] 1e06de8 WebGroup I SRVE0180I: [cs.war] [servlet] [Servlet.LOG]: DirectoryBrowsingServlet: init

  • Form Authentication Servlet  and MD5

    Dear forum,
    I have the following servlet to authenticate a user via form. If you go to the root url you get the login html and the authentication works fine but if the user knows the url of a specific html just by typing the url gives access to the page without going through the authentication. The website is composed of htmls and servlets. How can I force the authentication for the htmls and the servlets. I included at the bottom how I added the Login servlet to the web.xml. I suspect that the servlet definition in the web.xml is the problem.
    Also I would like to use MD5 encryption, would someone suggest how this can be accomplished.
    Thanks.
    This is the code:
    import java.io.*;
    import java.util.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.sql.*;
    import javax.sql.*;
    public class LoginServlet extends HttpServlet {
      public void doPost (
         HttpServletRequest     request,
         HttpServletResponse     response
        ) throws ServletException, IOException
      String item = request.getParameter("account");  
      doGet(request,response);
      public void doGet (
         HttpServletRequest     request,
         HttpServletResponse     response
        ) throws ServletException, IOException
       HttpSession session = request.getSession(true);
       PrintWriter out = response.getWriter();
         try {
              String driverName="sun.jdbc.odbc.JdbcOdbcDriver";
              String dbUrl="jdbc:odbc:Virtual_Library_DB";
              Class.forName(driverName);
              Connection db =DriverManager.getConnection(dbUrl,"","");
              if ((session.getAttribute("user") == null) || (!session.getAttribute("ip").equals(request.getRemoteAddr()))){
                   PreparedStatement pStmt = db.prepareStatement("SELECT * FROM Login WHERE Login.account =? AND Login.password=? ");
                   pStmt.setString(1, request.getParameter("account"));
                   pStmt.setString(2, request.getParameter("password"));
                            pStmt.setString(3, request.getParameter("level"));
                   ResultSet rs = pStmt.executeQuery();
                    System.out.println("hello");
                   if(!rs.next()){
                        System.out.println("Account is not valid.");
                        request.setAttribute("msg", "Account is not valid.");
                        RequestDispatcher rd = request.getRequestDispatcher("LoginInvalid.html");
                        rd.forward(request, response);
                   else do {
                        int id = rs.getInt(1);
                        String account = rs.getString(2);
                        session.setAttribute("user", new Integer(id));
                        session.setAttribute("account", account);
                        session.setAttribute("ip", request.getRemoteAddr());
                        System.out.println("User " + session.getAttribute("user") +" has logged on.");
                        request.setAttribute("msg", "User has logged on.");
                        RequestDispatcher rd = request.getRequestDispatcher("index.html");
                        rd.forward(request, response);
                   } while(rs.next());
                   rs.close();
              else {
                   System.out.println("User has already logged on.");
                        request.setAttribute("msg", "User has already logged on.");
                        RequestDispatcher rd = request.getRequestDispatcher("index.html");
                        rd.forward(request, response);
              db.close();
         catch(Exception exp){
              System.out.println("Exception: "+ exp);
       out.close();
    web.xml
    <servlet>
        <servlet-name>LoginServlet</servlet-name>
        <servlet-class>LoginServlet</servlet-class>
      </servlet>
    <servlet-mapping>
        <servlet-name>LoginServlet</servlet-name>
        <url-pattern>/LoginServlet</url-pattern>
      </servlet-mapping>

    Check the session in the servlets that are allowed only for logged-in users.
    public class ServletUtils
        public static boolean checkLogin(HttpServletRequest request, HttpServletResponse response)
            HttpSession session = request.getSession(false); // false = don't create a new session if not logged in
            if (session != null)
                return true;
            Logging.log("tried to access page without login, redirecting to login");
            ...redirect to login.html...
            return false;
        // At the start of your doGet()'s:
        if (!checkLogin(request, response))
            return;Do you really need static documents to be authenticated? dot.gif's and all? Someone can make a zip file of them anyway and post it to their own web site or Kazaa.
    If you have a couple of html pages you want authenticated, easiest is to write them as servlets (+ maybe JSP's) and do the login check there.
    Ok, let's say you have ...what, an "image database" (heh) that you want available to logged-in users only. Write a servlet that serves those pages. That servlet checks the session, and then copies the appropriate file to the user (remember to set content type; consider caching the files if hit rate is very high.) The servlet would be called like /images/show?id=gerbilsex/closeup.gif to fetch the named file. Put the files outside the web server's document directory so they are not accessible except through the servlet. Perform strict checks on the file name to disallow nastiness like id=../../../etc/passwd. A similar database solution is also possible. Another variant is to map a servlet to a "virtual directory name" and get the actual file name from the URL path -- similar to the ?id= solution, except the URLs don't have parameters.
    About md5: md5 isn't an encryption algorithm, it is a hash algorithm (aka "message digest" or "fingerprint"). It can't be decrypted. What do you really want to accomplish - encryption or hashing?

  • Need help to set values from web.xml in a jsp class

    Hey :-)
    I`m trying to get value from my web.xml file into a jsp class. The problem is that the value always retur null. My web.xml file is replaced in the WEB-INF directory where should be. Here is my web.xml
    <servlet>
    <servlet-name>Html</servlet-name>
    <servlet-class>Html</servlet-class>
    <init-param>
    <param-name>html_test</param-name>
    <param-value>Value I want have in my jsp class
    </param-value>
    </init-param>
    </servlet>
    And her i my java class who don`t work:
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    import javax.servlet.ServletConfig;
    public class Html extends BodyTagSupport
    String title="";
    String html_test;
    ServletConfig config;
    public void doInitBody() throws JspException
    html_test = config.getInitParameter("html_test");
    }//End of method doInitBody()
    public int doStartTag() throws JspException
    try
    JspWriter out = pageContext.getOut();
    out.print( "<HTML>\n" );
    out.print( "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" );
    out.print( "<BODY>\n" );
    out.print( "<BR><H1>" + html_test + "</H1>" );
    And here are my html_test variable return null.
    I hope somone can help me, duke dollars will be given away for the solution answer.
    paulsep

    Nothing seems to work, have change the string and rewritten the web.xml file to:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
              <context-param>
                   <param-name>html_test</param-name>
                   <param-value>Value I want have in my jsp class</param-value>
              </context-param>
    </web-app>

Maybe you are looking for