Setting up JNDI resources in web.xml only

Hi,
I'm using Tomca 4.0 LE and JDK 1.4.0_01.
I've been using a database connection pool on my local machine by editing the server.xml file and web.xml. However, I need to move the webapp onto a web hosting compaines server (same tomcat and jdk version). I cannot edit the server.xml file, so I need to set up my JNDI resource in web.xml only.
I have done this (in web.xml):
<resource-ref>
      <res-ref-name>jdbc/ocb_clients</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref> Now, before when I had this all set up in web.xml, I had a list of <ResourceParams> within the <context> element:
<ResourceParams name="jdbc/ocb_clients">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
     <name>username</name>
     <value>username_here</value>
    </parameter>
    <parameter>
     <name>password</name>
     <value>password_here</value>
    </parameter>          
    <parameter>
       <name>driverClassName</name>
       <value>org.gjt.mm.mysql.Driver</value>
    </parameter>       
    <parameter>
      <name>url</name>
      <value>jdbc:mysql://localhost:3306/ocb_clients</value>
    </parameter>
  </ResourceParams>These parameters are obviously needed for the datasource to work. How can I set these up just using web.xml?
Also, this code is from a servlet that I have loading on tomcat startup. Will this still work with the new configuration?
public void init() throws ServletException
     DataSource ds = null;       
     try
       //Set up the inital context
       Context ctx = new InitialContext();
       //Look up the database
       ds = (DataSource) ctx.lookup("java:comp/env/jdbc/ocb_clients");
     catch(NamingException nameE)
       System.err.println("Error looking up database: " + nameE);
     //Add the datasource to the application scope
     getServletContext().setAttribute("ocbDatabase", ds);
  }Any help is greatly appricated,
Thanks, Mel.

I am Having exactly the same problem with tomcat 5.0. I have tried to do everything mention as solutions at different fourums but I failed.
BTW I am using MySQL
Thanks
Dibakar

Similar Messages

  • Setting web pages resource in web.xml

    Hi all
    I want to set the location of my jsps in a different folder of my web app root.
    I mean i have a subfolder of web app root and i want to set this subfolder as web pages location.
    Any idea ? setting anything with the web.xml?

    you need not set a different path.. u can just type in folder name in the browser
    http://localhost ..../folder/index.jsp
    (immediately after the port number)

  • How to set the JNDI resources and params

    I am trying to connect my Crystal reports to my JSP page.
    I am using MySql DB and TomCat 4.1
    My web.xml is in the right place and contains the JNDI name (jdbc/MyDB)
    I was able to accomplish the following:
    1) Setting the connection pool and
    2) Able to specify the JDBC database option and was also able to generate the report in the designer using this JDBC option connectivity.
    However, when I try to run the report from the JSP page, it gives me the following error:
    javax.servlet.jsp.JspException: Report location is not specified in the configuration file     at
    com.crystaldecisions.report.web.viewer.taglib.ReportServerControlTag.doEndTag(Unknown Source)
         at org.apache.jsp.testing_jsp._jspx_meth_crviewer_viewer_0(testing_jsp.java:159)My CrystalReportEngine-config.xml resides in
    C:\Program Files\Apache Group\Tomcat 4.1\webapps\WebModule1\WEB-INF\classes
    and it contains the following
    <CrystalReportEngine-configuration>
      <reportlocation>../..</reportlocation>
      <timeout>10</timeout>
      <keycode>Azzzzzzzzzzzzzzzzzzzzzz</keycode> </CrystalReportEngine-configuration>
    My report that I am trying to execute resides in the root of my application (where it supposed to be).
    This lead me to believe that I probably need to specify a JNDI datasource.!! Do you agree? If so, how can I specify the
    JNDI Provider URL
    JNDI Username (is this the tomcat admin user name)?
    JNDI PWD
    Initial CONTEXTReally appreciate any help you can offer

    Can anyone tell me where to post the previouse message to get a solution, or may be a hint?
    If i am doing anything wrong to not get a response, please let me know so i can reward it or correct it.
    thanks

  • Setting the JNDI resource on tomcat

    I was given this website to(http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-resources-howto.html) try set up the JNDI resource. I have tried to make sence but I can't be sure exactly what to do they are so many files. Does anyone know a step by step website or can anyone explain it in simple english. All I am trying to do is set it up so I can use JSTL tags to reference a database.

    Thanks for the point in direction. I got it to work the way i needed it too.
    I was wondering however... when the access manager is first installed, there are no host identifiers and so the resources that you setup before you enable any host identifiers are for all hosts. As soon as you configure at least one host identifier, you loose the ability to set up a resource that is for all hosts.
    For example, the /access and /identity resources that are setup for you during installation are for "all" hosts. Is it possible to set up other resources like this after you start using host identifiers?
    Also, if you use host identifiers, is it necessary to go back and change the /identity, /access, or any other resource that was configured before the use of host identifiers to now include a host identifier? If not, are there any security concerns or is this perfectly fine?

  • JSF - How to set up tag libs in web.xml file?

    Hello all,
    I have a doubt... that in an JSF application we are using two tag libraries, one for the core and other for html components. Both these *.tld files are jared inside "jsf-impl.jar" file.
    The problem is that when i start the web server (Tomcat4.0.6) the console shows that taglib tag must be configured... this means that we have to specify the "<taglib></taglib>" elements in the web.xml file of the jsf application... but how do configure the jar file...
    please guide...

    Putting the JAR files in WEB-INF/lib and using the standard URIs in the taglib directives are all that's needed; the container locates the TLDs in the JAR files at startup.
    If this doesn't work, it's a bug in the container. You may want to upgrade to a later version of Tomcat; 4.0.6 is ancient, and may very well be buggy in this area.

  • IS ATG ROLLUP 7 +PATCH SET 19 (FORMS) APPLY FOR WEB TIER ONLY

    Hi everyone,
    We are planning to apply ADI 7 + Patch set 19 and everything working great . But my question we have Three tier Apps(WEB,Con,Form,Report) ,WEB,DB
    We applied it on Apps tier but there is a node have only web tier and ADI 7 and patch set 19 for forms there is no relation with Web Tier.
    in this case is it need to apply it on this node also as we know from oracle "You must apply any patches that you apply it from first node on second node"
    What do you think ?
    Best Regards,

    >
    We are planning to apply ADI 7 + Patch set 19 and everything working great . But my question we have Three tier Apps(WEB,Con,Form,Report) ,WEB,DB
    We applied it on Apps tier but there is a node have only web tier and ADI 7 and patch set 19 for forms there is no relation with Web Tier.
    in this case is it need to apply it on this node also as we know from oracle "You must apply any patches that you apply it from first node on second node"
    What do you think ?Hi,
    If you only web tier and no APPL_TOP on that tier means you no need to apply the ADI7 and patchset 19 patch
    in this case is it need to apply it on this node also as we know from oracle "You must apply any patches that you apply it from first node on second node"it would be like You must apply any patches that you apply first in Admin node and on other nodes..
    -Rk

  • JNDI resources and Servlets � deployment question.

    Use of JSTL and Realms implies use of JNDI for accessing to DataSource by its string name. I can set up JNDI resources for a web-application using web.xml or/and context.xml. But web.xml is inside a WAR file. So it is impossible to deploy an application using single WAR file since web.xml must be edited first, and that requires of exploding WAR archive.
    The question is: is there some common practice how to make web applications configurable (database URI, etc) without editing of web.xml? Does it make sense to store settings using Preferences API and to declare JNDI resource within ContextListener class?

    Tomcat 5.5 uses a different format for data source configuration. You're using the Tomcat 4.x and 5.0 series configuration format. Downgrade Tomcat, or use the appropriate config:
    http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
    You'll want something like this:
    <Resource
       name="jdbc/HDCD"
       auth="Container"
       type="javax.sql.DataSource"
       username="miladmin"
       password="authorize"
       etc...
    />

  • Mime-type tag in web.xml and attachment download

    i have set a mime-type in web.xml as below:
    <mime-mapping>
         <extension>xls</extension>
         <mime-type>application/vnd.ms-excel</mime-type>
    </mime-mapping>
    And i have a simple jsp that only shows a table and i am making this jsp to get downloaded as an excel attachment. To make it possible i have written the following line in the JSP:
    response.setHeader( "content-disposition", "attachment; filename=myexcel.xls" );
    But i am not setting the content type first by writing:
    response.setContentType( "application/vnd.ms-excel" );
    since i have already mentioned the appropriate mime-type for excel files in web.xml.
    I am using both mozilla and IE. Both are showing file download dialog. But IE is able to correctly identify the type of the attachment and opens it up with Microsoft Excel whereas mozilla fails to identify the type, assumes it to be an HTML document and opens it up in a new window of IE.
    mozilla works fine only when i set the content type in the JSP itself. But IE works in all conditions even without having the mime-type tag in web.xml.
    If i have already specified the mime-type for particular type of file in web.xml, is there any requirement to set the content type again in the JSP/servlet?
    Please help. I even changed the mime-type for .xls (excel) files in web.xml and made it text/plain, but still the same thing is happening. IE is always showing the correct file type where as mozilla is taking it as an HTML document.
    i am using weblogic server 8.1.

    the web xml mime type setting are for static files served by the server...
    if you print a file directly to the output of the servlet, you must set the mime type, so DO write :
    response.setContentType( "application/vnd.ms-excel" );
    IE "works fine" because it also uses the file extension to decide the mime type... but in the absolute, it's a wrong behaviour

  • How to chage the welcome file in web.xml using creator?

    Hi guys,
    I want to set the welcome file in web.xml to index.html but every time I run my project in creator, creator replaces index.html by faces/index.jsp. I need the index.html to check if the browser enables cookies & javascript and then I redirect to index.jsp. If I change the web.xml in a common editor, build the war-file with ant and deploy the project with tomcat, everything is fine. but how can I change it in creator?
    thanks in advance

    Sorry, that doesn't make much sense.
    The XML you gave is a configuration file for txt2xml utility. It doesn't represent the output format.
    Are you a user of this utility?

  • Tomcat 404 error until I apply this change to my web.xml mapping

    What is the purpose of the /servlet/ portion of the url-pattern in the servlet mapping element below.
    If I use the first few lines I get a 404 class not found error
    If I include /servlet/ in the url-pattern element then my app works fine ?????
    //Does not work
    <servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>com.onjava.login</url-pattern>
    </servlet-mapping>
    //works !!
    <servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/servlet/com.onjava.login</url-pattern>
    </servlet-mapping>

    If the first mapping doesn't work and the second mapping works then my guess is that neither mapping is working. What may be happening is the invoker servlet may be enabled and that would explain why the /servlet url works.
    The invoker servlet is set up in the conf/web.xml file. This servlet will invoke a particular servlet using the class name and the /servlet url. In newer versions of tomcat the invoker servlet id disabled by default.
    Now the question is why does the servlet mapping not work? What version of tomcat are you running? Can you post the entire web.xml?

  • Help !!!  option to avoid overwriting  web.xml by DDInit

    Hi all,
    I am using java weblogic.marathon.ddinit.EarInit to generate web.xml only if it is not there.
    For some reason, it is overwritting existing web.xml.
    I am looking for the option which i can use to DDInit to avoid overwritting web.xml if it already exsits.
    Can anyone please tell me any such option is available.
    Thanks in advance

    Hello,
    This is a known issue and has been reported as an Enhancement Request through CR089093. As per this CR , this issue is fixed in future WSL 9.0 (Diablo) release.
    For more information on this CR please open a support case with BEA.
    Regards,
    Kuldeep Singh.

  • Override JNDI names in persistence.xml and @resource annotation

    I have a Java EE 7 application that I am developing for use with both GlassFish and WildFly, but I have discovered that both application servers use a slightly different format for specifying JNDI names.
    In GlassFish the persistence.xml file references the data source jdbc/myDataSouce, but in WildFly the data source needs to be java:/jdbc/myDataSource.The same is also true for classes that are annotated with @Resource. In GlassFish the annotation for a class using JavaMail would be @Resource(name = "mail/myMailSession"), but to deploy onto WildFly this would need to be @Resource(name = "java:mail/myMailSession").
    The only solution I've got at present is using Maven to create two different releases of the EAR file, with one EAR file containing a persistence.xml file with the data source jdbc/myDataSouce for use with GlassFish, and the second EAR file containing a persistence.xml file with the data source java:/jdbc/myDataSource for use with WildFly. Unfortunately, I haven't found a solution for the @Resource annotation.
    I've taken a look at the documentation for glassfish-application.xml and glassfish-ejb-jar.xml and have tried using resource-ref to override the JNDI names but the application fails to deploy due to an error in the name.
    My question is does GlassFish provide any capability to override the JNDI names specified in the persistence.xml file and classes with the @resource annotation?
    Many Thanks
    Paul

    Have you been able to solve this? I'm attempting to understand what Web Server 7 can do with regard to Java Persistence and what elements of it require Glassfish.
    I've also spent great amounts of time in WS6.1 trying to figure out why a JNDI resource couldn't be found. The rules of thumb I've learned are:
    - Try dropping the *'java:/comp/env/* prefix; just use jdbc/pact part
    - Make sure all referrences (in web.xml and sun-web.xml) are identical with regard to that name.
    I'm hoping you're not still dealing with this (it's been two months!) but if anybody else stumbles on this, maybe it'll help them.
    Dave

  • How to configure a JNDI ressource in the web.xml file

    Hi,
    does someone know if there is a way to configure a JNDI ressource with its parameters only in the web.xml file ?
    In my case, the JNDI ressouce is an oracle database an its conenction paramters: driverClassName, username, password, etc...
    Actually, I put everything in the configuration file of Tomcat but I would like my war file to be 100% independent of the application server.
    Thanks in advance.
    Fred.

    I wrestled with this for a long time. I may have done something wrong, but to get my mySQL JDNI reference to work, I had to add it to the server.xml file. You can try with web.xml, but I eventually just got frustrated and put it in server.xml.
    The following is between two <context> tags:
    <Resource name="jdbc/instance_name_goes_here"
                   auth="Container"
                   type="javax.sql.DataSource"/>
              <ResourceParams name="jdbc/same_instance_name_here">
                   <parameter>
                        <name>username</name>
                        <value>user_name_goes_here</value>
                   </parameter>
                   <parameter>
                        <name>password</name>
                        <value>password_goes_here</value>
                   </parameter>
                   <parameter>
                        <name>driverClassName</name>
                        <value>jdbc_fully_qualified_class_name</value>
                   </parameter>
                   <parameter>
                        <name>factory</name>
                        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
                   </parameter>
                   <parameter>
                        <name>url</name>
                        <value>jdbc_connect_url_database_vendor_specific</value>
                   </parameter>
                   <parameter>
                        <name>maxActive</name>
                        <value>8</value>
                   </parameter>
                   <parameter>
                        <name>maxIdle</name>
                        <value>8</value>
                   </parameter>
              </ResourceParams>
    - Saish
    "My karma ran over your dogma." - Anon

  • Configuring a JNDI ressource in the web.xml file

    Hi,
    does someone know if there is a way to configure a JNDI ressource with its parameters only in the web.xml file ?
    In my case, the JNDI ressouce is an oracle database an its conenction paramters: driverClassName, username, password, etc...
    Actually, I put everything in the configuration file of Tomcat but I would like my war file to be 100% independent of the application server.
    Thanks in advance.
    Fred.

    I'm pretty sure you can't do it that way round. The logic of the thing is that database access URLs etc. tend to depend on the where the server is. The whole idea of these resources is to put the stuff that's specific to the server in server.xml and refer to it using names that should remain the same if you deploy your webapp on another server. Of, for example, you have test, stage and production servers running the same webapps but connecting to different databases.

  • What's the actual function of resource-ref in web.xml

    I was configuring JNDI datasource in tomcat and found an confusing fact.
    If I have the JNDI resource configuration in the context configuration of the project, I could get access to the JNDI element with or without the resource-ref configuration in my web.xml.
    Can someone tell me what exactly resource-ref does in the web application?
    Thank you.

    Thank you, Sunny.
    But I still don't quite understand.
    In Tomcat, this <resource-ref> seems to be optional, right?
    Plus, there should be a virtual name and actual location in the configuration.
    <resource-ref>
    <description>Resource reference to a factory for java.sql.Connection.</description>
    <res-ref-name>jdbc/mydb</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    So, is "jdbc/mydb" the virtual name or the actual location of the resource?

Maybe you are looking for