How to get Context paramters out of Tomcat web.xml file
The Documentation at Tomcat seems to suggest:
Context initialization parameters that define shared
String constants used within your application, which
can be customized by the system administrator who is
installing your application. The values actually
assigned to these parameters can be retrieved in a
servlet or JSP page by calling:
String value =
getServletContext().getInitParameter("name");
Now I want to write a jsp, where the user enters his username and pwd, and this contacts a jdbc connection bean. I want to store the driver name in the web.xml file. Now can some1 please suggest a method as to how I can extract this (It ain't that straightforward as suggested in tomcat doumntation. You cannnot call the above method ithout Servlet Initialization (actually to say ithout HTTP Connection). I succeeded when I had written a servlet, but can some1 please suggest an alternative (bcoz othrwise just to extract that I am writing a servlet).
Hope I am clear.
Thanks in advance.
Edit your web.xml file and add these entries,
<context-param>
<param-name>dbUrl</param-name>
<param-value>jdbc:oracle:thin:@server5:1521:pl2java</param-value>
</context-param>
<context-param>
<param-name>dbDriver</param-name>
<param-value>oracle.jdbc.driver.OracleDriver</param-value>
</context-param>
Place the above entries in between your already existing <web-app> and </web-app> tags.
Now in your jsp, you can use, <% application.getInitParameter(); %> and in servlet, getServletContext().getInitParameter();
Hope this helps.
Sudha
Similar Messages
-
How to get nodes and its attributes of an XML file usiong DOM parsing?
how to get nodes and its attributes of an XML file usiong DOM parsing?
i am new to XML parsing.......
Thanking you........import org.w3c.dom.Document;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException; ...
//Setup the document
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File("MY_XML_FILE.xml"));
//get elemets by name
String elementValue = doc.getElementsByTagName("MY_ELEMENT").item(0).getTextContent();
//This method can return multiple nodes, in this instance I get item(0) , first nodeRead the api for other methods of getting data. -
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 -
How to avoid inserting CheckSessionFilter in to the web.xml file?
Mobile Server modifies the web.xml during adding a .war-file to the publication. A new entry- CheckSessionFilter will be inserted inside the web.xml after uploading to the mobile server:
****************** inserted part **********************
<filter>
<filter-name>CheckSessionFilter</filter-name>
<filter-class>oracle.lite.web.CheckSessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CheckSessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
****************** inserted part **********************
Our application has own security-concept and don’t need this additional session checking.
How can we avoid including of CheckSessionFilter in to our web.xml?Don't do "add a war option" Instead, package your application using packaging wizard omitting the filter. Or, you can edit the WEB-INF/web.xml file on the mobile server after you deploy it.
Make you update the APPLICATIONS table
UPDATE APPLICATIONS
SET PUBLISH_TIME = SYSDATE
WHERE NAME = 'you application';
You application will be uploaded to:
STANDALONE
ORACLE_HOME/mobile_oc4j/j2ee/application/mobileserver/applications/yourapplication/WEB-INF/web.xml
IAS
ORACLE_HOME/j2ee/application/mobileserver/applications/yourapplication/WEB-INF/web.xml -
How to get information of error configuration in web.xml
Hi
Is there an API in the Java Servlet API that can give me information on the <error> tags of the web.xml.
Regards,
N�stor Bosc�nThat is XML file why u dont try JAXP (SAX) i.e XML parsers for that file
;) -
How to set the servlet context path manually in Tomcat web server.
I tested some servlets by putting them in the folder , which the tomcats examples application uses (ie Tomcat 4.1\webapps\examples\WEB-INF\classes\) and it appeared to be working fine.
I was calling the servlet like this : http://localhost:2006/examples/servlet/TestServlet
But when I installed my own WAR file in the server , the servlet is not working now. now the new location of my servlets is : Tomcat 4.1\webapps\MyApp\WEB-INF\classes\
and I'm trying to call the servlet like this : http://localhost:2006/MyApp/servlet/TestServlet
The error , what i'm getting is :
description :The requested resource (/MyApp/servlet/TestServlet) is not available.
Some body please tell where I'm making the mistake ? I believe this may have something to do with the servlet context path setting. If anybody has any idea , how to set the path..will be much appreciated.Thanx for your reply , at first I was not using any web.xml(since not mandatory) but even after using the web.xml file the error is coming . Please have a look into the contents of the web.xml file and let me know if you find any problem...
<?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>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>TestServlet</servlet-class>
</servlet>
</web-app>
one more thing I would like to tell you here. I was just looking into the configuration of Iplanet web server..I found that , there are options to set the servlet container path (like : - Prefix: /servlet
Servlet Directory: /ecomm/iplanet/nes60/product/docs/container )
so from here I came to know that "container " is the folder where we should put our servlets and it has URI as "servlet" but yet I'm not able to find any option in the Tomcat Web server to set the servlet container to any different directory.
If you have any idea please let me know. -
How can I get the context-parm from a web.xml file using struts?
Hello:
I need get the context-param from the web.xml file of my web project using struts. I want configurate the jdbc datasource connection pooling here. For example:
<context-param>
<param-name>datasource</param-name>
<param-value>jdbc/formacion</param-value>
<description>Jdbc datasource</description>
</context-param>
and then from any Action class get this parameter.
Similar using a simple server can be:
/** Initiates new XServlet */
public void init(ServletConfig config) throws ServletException {
for (Enumeration e = config.getInitParameterNames(); e.hasMoreElements();) {
System.out.println(e.nextElement());
super.init(config);
String str = config.getInitParameter("datasource");
System.out.println(str);
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
// res.setContentType( );
System.out.println("Got post request in XServlet");
PrintWriter out = res.getWriter();
out.println("nada");
out.flush();
out.close();
but only this works for init-params, if I use
<servlet>
<servlet-name>MyServlet</servlet-name>
<display-name>MyServlet</display-name>
<servlet-class>myExamples.servlet.MyServlet</servlet-class>
<init-param>
<param-name>datasource</param-name>
<param-value>jdbc/formacion</param-value>
</init-param>
</servlet>
inside my web.xml. I need something similar, but using struts inside the action class for that I can get the context-params and call my database.
Thank youTo get context parameters from your web.xml file you can simply get the ActionServlet object from an implementing action object class. In the perform (or execute) method make the following call.
ServletContext context = getServlet().getServletContext();
String tempContextVar =
context.getInitParameter("<your context param >"); -
How to get the return values from a web page
Hi all :
how to get the return values from a web page ? I mean how pass values betwen webflow and web page ?
thank you very much
Edited by: jingying Sony on Apr 15, 2010 6:15 AM
Edited by: jingying Sony on Apr 15, 2010 6:18 AMHi,
What kind of web page do you have? Do you have possibility to for example make RFCs? Then you could trigger events (with parameters that could "return" the values) and the workflow could react to those events. For example your task can have terminating events.
Regards,
Karri -
How to get user logged in to ironport web
How to get user logged in to ironport web by their username, time connected and the IP address?
The onbox reporting can only show what web traffic is currently being surfed. We can provide a near-real time view of this web traffic with a "Web Tracking Report".
However, there is not a report available that depicts what you're describing. (This information is best contained on the domain server). The closes we could get with the WSA is displaying which credentials we are currently caching. (Which users we've seen since within the surrogate timeout). This is possible with the authcache command on the cli.
~Tim -
How to get the full path instead of just the file name, in �FileChooser� ?
In the FileChooserDemo example :
In the statement : log.append("Saving: " + file.getName() + "." + newline);
�file.getName()� returns the �file name�.
My question is : How to get the full path instead of just the file name,
e.g. C:/xdirectory/ydirectory/abc.gif instead of just abc.gif
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
public class FileChooserDemo extends JFrame {
static private final String newline = "\n";
public FileChooserDemo() {
super("FileChooserDemo");
//Create the log first, because the action listeners
//need to refer to it.
final JTextArea log = new JTextArea(5,20);
log.setMargin(new Insets(5,5,5,5));
log.setEditable(false);
JScrollPane logScrollPane = new JScrollPane(log);
//Create a file chooser
final JFileChooser fc = new JFileChooser();
//Create the open button
ImageIcon openIcon = new ImageIcon("images/open.gif");
JButton openButton = new JButton("Open a File...", openIcon);
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int returnVal = fc.showOpenDialog(FileChooserDemo.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//this is where a real application would open the file.
log.append("Opening: " + file.getName() + "." + newline);
} else {
log.append("Open command cancelled by user." + newline);
//Create the save button
ImageIcon saveIcon = new ImageIcon("images/save.gif");
JButton saveButton = new JButton("Save a File...", saveIcon);
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int returnVal = fc.showSaveDialog(FileChooserDemo.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//this is where a real application would save the file.
log.append("Saving: " + file.getName() + "." + newline);
} else {
log.append("Save command cancelled by user." + newline);
//For layout purposes, put the buttons in a separate panel
JPanel buttonPanel = new JPanel();
buttonPanel.add(openButton);
buttonPanel.add(saveButton);
//Explicitly set the focus sequence.
openButton.setNextFocusableComponent(saveButton);
saveButton.setNextFocusableComponent(openButton);
//Add the buttons and the log to the frame
Container contentPane = getContentPane();
contentPane.add(buttonPanel, BorderLayout.NORTH);
contentPane.add(logScrollPane, BorderLayout.CENTER);
public static void main(String[] args) {
JFrame frame = new FileChooserDemo();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
frame.pack();
frame.setVisible(true);simply use file.getPath()
That should do it!Thank you !
It takes care of the problem !! -
How to setup web.xml files in Tomcat 4.0.6
Hi, I'm to new to Java Servlets. i am trying to run my first servlet but it's not showing up..can anyone help me out please!!!
I created a folders like this:
webapps/sumitapps/WEB-INF\classes\Forms\login.class
under sumitapps: i'm puttin all of my .html files(Logins.html)
under WEB-INF: i put web.xml file and classes folder
<?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>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>Forms.login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/Forms.login</url-pattern>
</servlet-mapping>
</web-app>
<Context path="/sumitapps" docBase="webapps/sumitapps" crossContext="true" debug="0" reloadable="true" trusted="false" >
</Context>
under my classes folder i put folder Forms where i'm keeping all of my .class files. my class file name is login.class
can anyone tell me why i cant run my servlets
<FORM method="POST" action="Forms.login"
name=userinfo onsubmit="return checkData()">
please help me out here
i can access my html page like this:
http://lcoalhost:8080/sumitapps/Logins.html
but when i enter userid and password it doesnt show anything..it takes me to http://localhost:8080/sumitapps/Forms.login
and shows cannot be displayedhave a look at www.moreservlets.com. There you can find a free pdf (part of the book, a whole chapter) that explains in deep the use of web.xml.
-
How to get the ablolute path of the web application in WebSphere?
How to get the ablolute path of the web application in WebSphere?
For example:
I have installed IBM WebSphere on D:\WebSphere\Appserver, and I created a new appliction named "myapp" on D:\myapp,. How can I get the absolute path of application "myapp"? In other words,how can I get the absolute path of the application's
root directory?In the WebSphere(default), what directory is the Java Bean's root directory ?
-
How to get to know the size of the biggest file in ContentServer
Dear colleagues!
Does anybody knows how to get to know the size of the biggest file in the ContentServer?
Vladimir
Edited by: Vladimir Pavlovsky on Mar 2, 2010 11:11 AMVladimir Pavlovsky wrote:>
> Dear colleagues!
> Does anybody knows how to get to know the size of the biggest file in the ContentServer?
Hi Vladimir,
I assume you want to know the size of the biggest file stored in the content server don't you?
This information is available through the content server API layer only - so better open this question in the knowlegde management forum.
regards,
Lars -
How to config the web.xml file, when I use Richfaces + RI 1.2?
Hi there:
I want to use Richfaces + RI 1.2 to build a project. I don`t know how to config the web.xml file.
By the way, my web server is Tomcat 6.0, my JDK's version is 6u6. I don`t want to use the facelets.
thanks.
lxmjust add this before *</web-app>*
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping> -
Web.xml file problem in tomcat
Hi i need help in this... its urgent
currently i just subscribe to a web hosting site and i need to start the private tomcat in the web server..
The followings are the instructions and i have follow them but i do not know how to create a web.xml file to store in the folder indicated for example a HelloServlet that im testing :
To setup servlet, you need to configure servlet into the file web.xml which needs to be placed in /var/www/html/WEB-INF directory.
www root directory or webapps:/var/www/htm
Classes directory located in: /var/www/html/WEB-INF/Classes/
There you will need to upload your Java class file.
Our default url-mapping for servlet is: /servlet/*
To check servlet in your browser: www.mydomain.net/servlet/HelloWorld
Jsp Files - Upload anywhere in /var/www/html
all the above steps are follow except the web.xml file which i suppose to write and store in the folder... but i actually try to write one but i still cannot load my servlet on the webpage... test on standalone tomcat works.
pls help its urgent!!!first sorry about cross posting the subject. i didnt know i am not suppose to do that. i post in a few forums that are related to my topic. sorry
The tomcat on the web server is of version Private J2EE / Tomcat 4.1.29 and the standalone tomcat i am using is also tomcat 4.1
the web.xml in my standalone server in root/web-inf/ is as follows and it is configure for authentication purposes. It works together with the tomcat-users.xml located on conf directory
<?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/j2ee/dtds/web-app_2_3.dtd">
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>
Restricted Area
</web-resource-name>
<url-pattern>/secure/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>manager</role-name>
<role-name>tomcat</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/Login.html</form-login-page>
<form-error-page>/Error.html</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>The Secure ROLE</description>
<role-name>manager</role-name>
<role-name>tomcat</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>
Restricted Area
</web-resource-name>
<url-pattern>/Customer/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>customer</role-name>
<role-name>tomcat</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/Login.html</form-login-page>
<form-error-page>/Error.html</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>The Secure ROLE</description>
<role-name>customer</role-name>
<role-name>tomcat</role-name>
</security-role>
</web-app>
using this web.xml, my stanalone web pages works fine for all servlets and jsp. however if i copy this over to the web server, i still cannot load my servlets and jsp. moreover it doesnt work for authentication purpose anymore. i don't know why too
i have try the codes you write before and it also doesnt work
the problem is i cannot get the support form the web hosting site. This is the link that suppose to teach me but it doesn not tell me how to configure my web.xml
https://www.eroute.net/JSPSupport.htm
Maybe you are looking for
-
Trying to transfer photos from mini sd card via adapter to iPad but get there are no photos message
Can anyone help, I am trying to transfer photos from a mini sd card via a apple adapter but get a message telling me there are no photos to transfer. Any ideas on a fix? Graham1955
-
Right now my ipod classic is set on 'music'. When I push the munu button, it will not go back to the main menus, but it will still go forward and select and play music normally. I tried resetting it by holding the menu and center buttons until the ap
-
Hi, The MAM 2.5 SR2 application is working fine on the desktop.But when I deploy the same application on a Pocket PC 2003 PDA I get the following exception when performing synchronization. com.sap.ip.me.smartsync.smartsynchronizationException The MA
-
How to Show last 6 months?
Hi Guys, I have a report that must show the last 6 months. If you open the report let's say on the 02.02.2010, this report must have the following columns and the following order: Jan 2010 - Dec 2009 - Nov 2009 - Oct 2009 - Sep 2009 - Aug 2009. Is it
-
100% width thumbnail container in lightbox slideshow?
Is there a way to make the thumbnail container 100% width in a lightbox slideshow? Basically I want a strip of 4-5 photos to span 100% of the width of the screen, then the user can click on an individual photo to bring up the larger version. I have i