Realising global Parameters like init-param in web.xml
Hallo,
I have a question:
How can I implement own parameters in a StudioCreator-application.
I have tried to edit the web.xml, first time it works.
(I read the parameters with ExternalContext.getInitParameter)
But later the web.xml was rewrited by the IDE and my parameters are gone.
Thanks for your help!
Regards
Wolfgang
Hallo,
I tried both. First the one in build. An than the one in src.
If I change the name or the Page (with rename)
my entries in the web.xml disappear.
My entries are:
<context-param>
<param-name>ldap_url_primary</param-name>
<param-value>ldap://WW004.SIEMENS.NET:389</param-value>
</context-param>
<context-param>
<param-name>domaene</param-name>
<param-value>WW004.SIEMENS.NET</param-value>
</context-param>
<!-- Faces Servlet -->
Thanks,
Wolfgang
Similar Messages
-
Init-params in web.xml are not loaded (Tomcat 4)
Hello all...
I register a servlet in webapps/<my-servlet>/WEB-INF/web.xml file, and pass 1 <init-param> tag. The file gets parsed (I know because when I made errors tomcat complained during initialization). However, when in the init method of the servlet I try to access this parameter, its not there. In fact, the servlet has NO init params at all.
=================================================
I have the following web.xml file
<?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>XServlet</servlet-name>
<servlet-class>com.fxcm.xml.xengine.xdas.XServlet</servlet-class>
<init-param>
<param-name>xengine.configFile</param-name>
<param-value>c:/projects/re/das.config/config.xng</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>XServlet</servlet-name>
<url-pattern>/xservlet</url-pattern>
</servlet-mapping>
</web-app>
=======================================================
I have the following servlet
* XServlet.java
* Created on May 6, 2002, 1:17 PM
package com.fxcm.xml.xengine.xdas;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletConfig;
import java.util.Enumeration;
import com.fxcm.xml.xengine.XEngine;
public class XServlet extends HttpServlet{
/** Initiates new XServlet */
public void init(ServletConfig config)
throws ServletException
for (Enumeration e = config.getInitParameterNames(); e.hasMoreElements();){
//This statement never gets printed because the loop never enters here since there are no init parameters
System.out.println(e.nextElement());
super.init(config);
String str = config.getInitParameter("xengine.configFile");
System.out.println(str);
XEngine.init(str.trim()); //This line throws NullPointer, because str is null since there are no initParameters.
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(XEngine.process(req.getInputStream()));
out.flush();
out.close();
================================================================
I get the follwoing error in the browser:
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at com.fxcm.xml.xengine.xdas.XServlet.init(Unknown Source)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:918)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:655)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:400)
Please help.
Thank you,
ElanaI know what the problem is. If you call servlet with the default URL (http://host/app/servlet/package.Servlet) than Servlet DOES NOT read init parameters. I don't know why it was designed this way.
To make servlet read init parameters, you have to assign it a name and then call it with that name, like this:
<servlet>
<servlet-name>ServletName</servlet-name>
<servlet-class>package.ServletClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletName</servlet-name>
<url-pattern>/app/path/ServletName</url-pattern>
</servlet-mapping>
You can then call servlet using path specified in url-pattern and read init parameters in the normal way. -
Significance of context param in web.xml to initialize any variable?servlet
I am writing a standalone web appplication for rss (xml) creation where i am having jsp servlets class etc.
Now to write rss.xml and read it back in application i have temporarily used c:\\rss.xml but to make it capable working in web application which can be uploaded in website i need to make it configurable i need to kep it in context param of web.xml and in init() method of servlet of my application what exactly i should do there.what i have tried is this :
public class Startup extends HttpServlet {
private static String rssFeed;
private ServletContext ctx;
Logger log = Logger.getLogger(Startup.class);
public void init(){
log.debug("Initializing APPLICATION CONTEXT Variables");
ctx = getServletContext();
rssFeed = (String)ctx.getInitParameter("RssFeed");
log.debug("Rss : " + rssFeed);
String rssFile = this.getServletContext().getRealPath("") + File.separator + "WEB-INF" + File.separator + "rss.properties";
Properties property = new Properties();
try{
InputStream propertiesFile = new FileInputStream(rssFile);
property.load(propertiesFile);
catch (IOException e) {
log.error("IOException during domainValuesList file Reading");
e.printStackTrace();
log.error("Exception while loading AllowedDomainValues file");
log.debug("Domain Values Lists Updated");
/** Get Host Name (Server Name) where application is hosted on
public static String getRssFeed(){
return rssFeed;
after that i called this startup servlet class in other servlet taken this getRssFeed()
stored it as string passed as parametr to other class where i need to call it but there i am getting null pointer exception which says not initialized.
even what i have written in web.xml is here:
<context-param>
<param-name>RssFeed</param-name>
<param-value>c:\\rsshandler.xml</param-value>
</context-param>
<servlet>
<servlet-name>Startup</servlet-name>
<servlet-class>src.Startup</servlet-class>
<init-param>
<param-name>RssFeedConfig</param-name>
<param-value>/WEB-INF/rss-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Startup</servlet-name>
<url-pattern>/Startup</url-pattern>
<load-on-startup>1</load-on-startup>
</servlet-mapping>
i tried what i know or understood but its not working.
one more thing i have doneis:created rss.properties files in web-inf
lines added are
rssfeed=c:\\rsshandler.xml
but even i am not getting this why
or what sholud i do here.
this thing needs to be configurablewhich we can change later easily.
any suggestions.
thanks
vijendraBen -
There can be init params for the servlet or for the servlet context. For the servlet, this looks like:
<servlet>
<servlet-name>InitServlet</servlet-name>
<servlet-class>package1.InitServlet</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>Hello From Initialization Parameter</param-value>
</init-param>
</servlet>
in the web.xml file, and is accessed using:
public void init(ServletConfig config) throws ServletException
super.init(config);
message = config.getInitParameter("message");
For a servlet context init param, you define it as you did using the web.xml settings editor:
<context-param>
<param-name>hello</param-name>
<param-value>hi</param-value>
</context-param>
This is accessed using:
public void init(ServletConfig config) throws ServletException
super.init(config);
message1 = config.getServletContext().getInitParameter("hello");
Hope this helps,
Lynn
Java Tools Team -
Generated JSP reports and context-param in web.xml
I have what I believe to be a problem when using .jsp files generated from reports builder (actually, it looks as if the problem is in the reports tag library. When adding a context-param to web.xml, I get an error when compiling the following line:
<%@ taglib uri="/WEB-INF/lib/reports_tld.jar" prefix="rw" %>
Error(1): oracle.xml.parser.v2.XMLParseException: Invalid element 'context-param' in content of 'web-app', expected elements '[taglib, resource-ref, security-constraint, login-config, security-role, env-entry, ejb-ref]'.
Note that I can read the context param and no other JSP pages seem to care, just those with the Reports Tag library.
Regards,
JeffBen -
There can be init params for the servlet or for the servlet context. For the servlet, this looks like:
<servlet>
<servlet-name>InitServlet</servlet-name>
<servlet-class>package1.InitServlet</servlet-class>
<init-param>
<param-name>message</param-name>
<param-value>Hello From Initialization Parameter</param-value>
</init-param>
</servlet>
in the web.xml file, and is accessed using:
public void init(ServletConfig config) throws ServletException
super.init(config);
message = config.getInitParameter("message");
For a servlet context init param, you define it as you did using the web.xml settings editor:
<context-param>
<param-name>hello</param-name>
<param-value>hi</param-value>
</context-param>
This is accessed using:
public void init(ServletConfig config) throws ServletException
super.init(config);
message1 = config.getServletContext().getInitParameter("hello");
Hope this helps,
Lynn
Java Tools Team -
Init parameter in web.xml throwing an error..?
OK.. this is probably going to sound strange, but here goes:
Here is my entry in the web.xml:
<servlet>
<servlet-name>ServletTestRunner</servlet-name>
<servlet-class>
org.apache.cactus.server.runner.ServletTestRunner
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletTestRunner</servlet-name>
<url-pattern>/ServletTestRunner</url-pattern>
</servlet-mapping>Everything works fine - I pull up the servlet with the following URL (http://localhost:7001/CDCAppWeb/ServletTestRunner?suite=com.testcases.decision.service.SendCreditRequestBeanTest)
, and receive the results in XML format. However, if I change the web.xml to have the following:
<servlet>
<servlet-name>ServletTestRunner</servlet-name>
<servlet-class>
org.apache.cactus.server.runner.ServletTestRunner
</servlet-class>
<init-param>
<param-name>xsl-stylesheet</param-name>
<param-value>cactus-report.xsl</param-value>
</init-param>
</servlet>(notice the cactus-report.xsl init-param entry) - the servlet does not work. Actually, NONE of the other servlets in my application work when I put in this init-param for the ServletTestRunner. I have verified that the xsl is in the classpath (WEB-INF/classes).
What I am missing... any ideas?I know what the problem is. If you call servlet with the default URL (http://host/app/servlet/package.Servlet) than Servlet DOES NOT read init parameters. I don't know why it was designed this way.
To make servlet read init parameters, you have to assign it a name and then call it with that name, like this:
<servlet>
<servlet-name>ServletName</servlet-name>
<servlet-class>package.ServletClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletName</servlet-name>
<url-pattern>/app/path/ServletName</url-pattern>
</servlet-mapping>
You can then call servlet using path specified in url-pattern and read init parameters in the normal way. -
hy,
can anybody help me with a problem?
Got following init-param in web.xml with <?xml version="1.0" encoding="ISO-8859-1"?>
set at the beginning.
<init-param>
<param-name>removeTemplateCache</param-name>
<param-value>/content/admin/remove?cache=templates&id=</param-value>
</init-param>
Deploying fails with SAXException saying:
Deployment descriptor "web.xml" is malformed, check against the DTD: The reference
to entity "id" must end with the ';' delimiter. (line 218, column 56)
What do I need to do to handle "special characters" in the Deployment Descriptors
?? Only Escaping doesn´t really work ..
Thanks for input.
Greetings
Seems to be a problem nobody want to answer to ..
Tried a little and found something that worked:
<?xml version="1.0" encoding="UTF-8"?>
<init-param>
<param-name>removePageCache</param-name>
<param-value>/content/admin/remove?cache=pages&id=</param-value>
</init-param>
The wonder ist called unicode and can be found in more details at: www.unicode.org
"Markus Eisele" <[email protected]> wrote:
>
>hy,
>
>can anybody help me with a problem?
>Got following init-param in web.xml with <?xml version="1.0" encoding="ISO-8859-1"?>
>set at the beginning.
>
><init-param>
> <param-name>removeTemplateCache</param-name>
> <param-value>/content/admin/remove?cache=templates&id=</param-value>
> </init-param>
>
>Deploying fails with SAXException saying:
>
>Deployment descriptor "web.xml" is malformed, check against the DTD:
>The reference
>to entity "id" must end with the ';' delimiter. (line 218, column 56)
>
>What do I need to do to handle "special characters" in the Deployment
>Descriptors
>?? Only Escaping doesn´t really work ..
>
>Thanks for input.
>
>Greetings
-
Simplest way to modify properties from web.xml
I'm testing a very small Web application which uses init-params in web.xml for configuration. For manual testing purposes, I need to be able to change the values of these as easily as possible, preferably from the WebLogic admin console. (I can do it from the console on Websphere App Server, and on Tomcat by editing a file which is immediately re-read.) We don't currently use deployment descriptors in any way and this is only a test of basic code functionality, not of deployment mechanisms, so the change can be as quick-and-dirty as you like. I'm using WebLogic v10 on Linux.
Thanks,
PeteAnother option for you may be to deploy the application in exploded format and use weblogic.Deployer or WLST to redeploy the application :
http://edocs.bea.com/wls/docs100/deployment/autodeploy.html
This would be slightly more similar to your Tomcat deployment, but requires a few more steps. -
Best practice for loading config params for web services in BEA
Hello all.
I have deployed a web service using a java class as back end.
I want to read in config values (like init-params for servlets in web.xml). What
is the best practice for doing this in BEA framework? I am not sure how to use
the web.xml file in WAR file since I do not know how the name of the underlying
servlet.
Any useful pointers will be very much appreciated.
Thank you.It doesnt matter whether the service is invoked as part of your larger process or not, if it is performing any business critical operation then it should be secured.
The idea of SOA / designing services is to have the services available so that it can be orchestrated as part of any other business process.
Today you may have secured your parent services and tomorrow you could come up with a new service which may use one of the existing lower level services.
If all the services are in one Application server you can make the configuration/development environment lot easier by securing them using the Gateway.
Typical probelm with any gateway architecture is that the service is available without any security enforcement when accessed directly.
You can enforce rules at your network layer to allow access to the App server only from Gateway.
When you have the liberty to use OWSM or any other WS-Security products, i would stay away from any extensions. Two things to consider
The next BPEL developer in your project may not be aware of Security extensions
Centralizing Security enforcement will make your development and security operations as loosely coupled and addresses scalability.
Thanks
Ram -
How to set global parameters? (Best Practice?)
Dear all,
I've experience with Infor Performance Management tools, Qlikview and also SAP Business Objects Reporting. As for last week i'm new to Microsoft Reporting Services. In our current environemnt we're setting up a Report Structure on top of an Analysis Service
Cube.
Currently I'm creating various reports (which works fine) on the mentioned Analysis Service Cube.
My current question is, if there is a best practice to create reports with global variables? We'll have a package of ~20 reports which all relate to the same data source. My approach is that i'll define the reports, but the global parameters like "Current
year", "Last year" etc. should be defined on a global page. That's the way I would have done it in the other BI tools.
How is this done best in MS Reporting Services? Should i add an additional flat SQL server source and put the values in some ref tables? Or script the global parameter?Hi Praveen G,
this blog was one of the sources I already found.
I was searching for the "official" way to set the default-workbook - without manipulating the tables programmaticaly (and possibly inconsistant).
Best regards,
Marco -
ISA changing web.xml parameters for ordering
Dear all,
I have the following problem. I would like to set the web.xml parameters in such a way that when I click add to basket from a product, to create a basket directly and add it rather than navigating to createdocument.jsp and having to choose between order and order template. I think this is possible, could someone please tell me some details on how to do it?
thank you very much in advanceHello Alkis!
Do you want to disable choose document type and create only a Basket type (neither Order nor Quotation) document while choosing product from product catalog?
Please give more clear requrements.
regards, Lev -
Help on web.xml file, what if the parameters contains key words ?
Hi:
I am just wondering what should I do if I want to include key words suchs
as <param> in web.xml file for a servlet config.
Example:
<servlet>
<servlet-name>testServlet</servlet-name>
<parameter>
<param-name>some name</param-name>
<param-value>some value</param-value>
</parameter>
</servlet>
What should I do if I want to repleace 'some value' with '</param-value>some
value' and still to prevent the engine to terminate parsing the param-value
at the fake ending? Is there a standard way in XML to distanguish that?
(in URL format it can be replaced %xx for some chars).
ie,
<param-value> </param-value>some value</param-value>
where the second </param-value> is the real ending.
Thank you!
GangHi!
You can use "& lt ;" and "& gt ;" xml entities for that. Or wrap text element in <![CDATA[...]]> section.
Regards,
Ignat. -
9.0.3, web.xml, context-param
Using documentation found on oracle's website, where I needed to have a specific initialization parameter, I setup a context-param in web.xml. In 9.0.2, I got a warning (and posted here but got no response) but was able to continue. In 9.0.3 I can't run my project when I include this parameter.
Here's what I add to web.xml
<context-param>
<param-name>ReportServerURL</param-name>
<param-value>http://localhost:8888/reports/rwservlet</param-value>
</context-param>
when trying to compile, I get:
Error(76,18): Invalid element 'context-param' in content of 'web-app', expected elements '[taglib, resource-ref, security-constraint, login-config, security-role, env-entry, ejb-ref]'.
Any ideas?
Thanks,
JeffIf only you would see web-app.dtd you could know that context-param must be enclosed in web-app and be at certain place. See that (from web-app.dtd):
<!ELEMENT web-app (icon?, display-name?, description?, distributable?,
context-param*, filter*, filter-mapping*, listener*, servlet*,
servlet-mapping*, session-config?, mime-mapping*, welcome-file-list?,
error-page*, taglib*, resource-env-ref*, resource-ref*, security-constraint*,
login-config?, security-role*, env-entry*, ejb-ref*, ejb-local-ref*)> -
Web.xml file not being read
Hello, I did a quick search but could not find an answer to my specific problem. (this is also my first night tackling servlets) i hope this hasnt been answered before. here goes...
i'm using Tomcat 4.1 and this is my file structure where i put my servlets:<intstall dir>/webappps/ROOT/WEB-INF/classes/TestPackage.
this is my code for the servlet
package TestPackage;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Example using servlet initialization. Here the message
* to print and the number of times the message should be
* repeated is taken from the init parameters.
public class ShowMessage extends HttpServlet
private String message;
private String defaultMessage = "No message.";
private int repeats = 1;
public void init(ServletConfig config) throws ServletException
//Always call super.init
super.init(config);
message = config.getInitParameter("message");
if (message == null)
message = defaultMessage;
try
String repeatString = config.getInitParameter("repeats");
repeats = Integer.parseInt(repeatString);
catch(NumberFormatException nfe)
//do nothing
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "The ShowMessage Servlet";
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n" +
"<HTML>\n" +
"<body bgcolor=\"#FDF5E6\">\n" +
"<h1 align=center>" + title + "</h1>");
for(int i=0; i<repeats; i++)
out.println(message + "<br>");
out.println("</body></html>");
}my web.xml file is in <intstall dir>/webappps/ROOT/WEB-INF. it looks like:
<?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>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>
ShowMsg
</servlet-name>
<servlet-class>
TestPackage.ShowMessage
</servlet-class>
<init-param>
<param-name>
message
</param-name>
<param-value>
Shibboleth
</param-value>
</init-param>
<init-param>
<param-name>
repeats
</param-name>
<param-value>
5
</param-value>
</init-param>
</servlet>
</web-app>when i access the servlet i get "No message" one time which is the default message. Any ideas as to why its not picking up the init parameters. I've restarted my laptop and started and stopped Tomcat a few times and i always get the default message...i also tried ShowMessage in replace of ShowMsg as the <servlet-name>, to no avail. I also tried removing the package name in the <servlet-class>, still nothing. Is there another web.xml file some where else that i need to update?
Thanks! (sorry for the long code)
BBThe doGet method works if you are sending data from a form using get method. It is better to use service method.
-
C:import and web.xml
Im using <c:import url="http://path_to_html" />. I want to put this value in the web.xml using context param. The problem is I don't know how my c:import tag will refer to that context param inside web.xml. Can anyone give a solution? Thanks.
web.xml
<context-param>
<param-name>abc</param-name>
<param-value>http://path_to_html</param-value>
</context-param>
JSP
<c:import url="<%= application.getInitParameter("abc") %>"></c:import>More info for c:import
http://www.onjava.com/pub/a/pub/a/onjava/2002/05/08/jstl.html?page=2
* Absolute URL: <c:import url="http://sample.com/Welcome.html"/>
* Relative URL (to the current context): <c:import url="/copyright.html"/>
* Relative URL with a foreign context: <c:import url="/myLogo.html" context="/common"/>
* FTP resource: <c:import url="ftp://ftp.sample.com/myFile"/> -
Please let me where to put web.xml in Oracle Application Server and how to deploy an application in Application server.
Debu,
We are not using OC4J. We are using apache for our application. We are placed our web.xml in Web-inf folder. But we are unable to get parameters or other functionality using web.xml. Can you tell me how to handle web.xml in this case.
Thanks
Sudha
Maybe you are looking for
-
How can I hold a frame of a clip?
I want to hold the first frame of a clip, then play the clip, then hold the last frame. Seems like there's some time remapping tools somewhere but I can't figure this out. I can't just take a screen shot and set that as the still because this is one
-
Internet Explorer 8 with Adobe Reader 11 in one package - embedded PDF problem
Hello, I am trying to package Internet Explorer 8 together with Adobe Reader 11 in ThinApp 5 for Windows 7. I am capturing on clean Windows XP with IE6. Of course, I am using "IEShims.dll" for IE8 in order to make it work in ThinApp. From the first l
-
Problem in Generating work schedule manually
hi all, I m facing problem while generation work schedule manually where i m not getting calender according to PWS. i m working for chemical industry where every level have different WSR and off eg: for manager SUN off General shifts MON off afternoo
-
Executing workflow after import
Hello all, Im trying to automatically launch a workflow which contains only one assignment. It is active and configured with the Record Import Trigger Action on Data Manager. On Import Manager, I have selected it on the Checkout/Workflow option.
-
Two Oracle XA connections fails
We experience problems when using more than one Oracle XA-resource from inside an EJB context under WSAD 5.1. It looks like the Oracle jdbc-driver isnt XA-complient with itself ;) We use the following configuration: - Oracle9i 9.2.0.3 - Oracle9i_9.2.