Different behaviour on servlet w/o servlet-mapping and init parameters

I was playing around and found, that the init-parameter of a servlet is always null if there is no servlet mapping. I did not define a servlet mapping because I used the servlet only for for (named) dispatching (client usage should not be allowed).
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <servlet>
    <servlet-name>InitParamServlet</servlet-name>
    <servlet-class>test.InitParamServlet</servlet-class>
    <init-param>
      <param-name>param1</param-name>
      <param-value>value1</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>InitParamServlet</servlet-name>
    <url-pattern>*.initparam</url-pattern>
  </servlet-mapping>
</web-app>
InitParamServlet.java:
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class InitParamServlet extends HttpServlet{
  private static final long serialVersionUID = 1L;
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    pw.write(getServletName());
    pw.write(": param1=" + getInitParameter("param1"));
}The URL http://localhost:8080/xxx/servlet/test.InitParamServletreturns org.apache.catalina.INVOKER.test.InitParamServlet: param1=null
(on Tomcat), and the call to the same servlet with URL http://localhost:8080/xxx/test.initparamreturns InitParamServlet: param1=value1 instead (the correct init parameter value)!
The same happens with jetty. This looks strange for me; I would expect the same behaviour for the servlet (independent from servlet-mapping-tag in the web.xml).

When you call the url
http://localhost:8080/xxx/servlet/test.InitParamServlet
you are actually calling the invoker servlet that is defined in the default conf/web.xml. If you look at this web.xml file you will see that the invoker is mapped with the pattern "/servlet/*" which maps to the above url. The request goes to this servlet which parses the url and then calls the InitParamServlet class.
When you call the url
http://localhost:8080/xxx/test.initparam
you are matching the url pattern you defined in the WEB-INF/web.xml file ("*.initparam"). This time the request goes to servlet instance that you defines in the servlet naming tags as "InitParamServlet" and since you defined init params they are populated.
Note that these urls will also match the "*.initparam" pattern
http://localhost:8080/xxx/XXXXX.initparam
http://localhost:8080/xxx/badpackage.initparam
http://localhost:8080/xxx/A.initparam
Most people would have simplely defined the second servlet mapping as "initparam" and accessed the servlet with the url
http://localhost:8080/xxx/initparam

Similar Messages

  • Different behaviour of a plug in in CS6 and CS5.5

    I've noticed a difference in a plugin behaviour in CS6 and CS5.5.
    In a SequenceSetup function the following call generates a PF_Cmd_ARBITRARY_CALLBACK in CS6 with the PF_Arbitrary_FLAT_SIZE_FUNC state of extra parameter. The same PF_Cmd_ARBITRARY_CALLBACK appears later in a plugin work and doesn't work properly in CS6. Though in CS5.5 there is no problem with this function, it doesn't generate any weird events.
    suites.ParamUtilsSuite1()->PF_GetCurrentState(in_data->effect_ref, &seqData->curSessionParamState); (code for CS5.5)
    suites.ParamUtilsSuite3()->PF_GetCurrentState(in_data->effect_ref,PF_P aramIndex_CHECK_ALL, NULL, NULL, &seqData->curSessionParamState); (updated code for CS6, in respect that the signature of PF_GetCurrentState has changed)
    I work in Windows 7, x64. CS6 is 11.0.0.378 version, CS5.5 is 10.5.0.253 version. The only change between these two version of the plug in is the PF_GetCurrentState signature. So I suppose that the problem is inside a new SDK. But I have no guess where it may be.. Do you have any idea what might have changed in CS6 to provide such an error?

    Hi Niakris,
    Thanks very much for closing the loop and reporting back what worked for you.  As to why there is a difference between CS5.5 and CS6, one of the engineers here explains:
    "I assume the behavior change is due to me making code in certain libraries thread-safe, and explicitly disallowing the execution of certain callbacks on anything other than the main thread. If it worked before CS6, it worked by accident, and was very unsafe to do."
    Glad to have you testing compatibility with CS6!
    Cheers,
    Zac

  • Different number of records in RSA3 for Full and INIT

    Hi All,
    I am about to load the data from 0FI_GL_4 and checked it in RSA3 for the number of records. It returned different number of records when I run the extract with options 'F' and 'C'. Why is it so? This is the first time I am loading the data into BW for this datasource. I would expect the number of records to be same if I do either a full extract or an init but surprised by seeing different number of records.
    Best Regards,
    James.

    Hi James,
    Probably it's because of the time stamps stored in table BWOM2_TIMEST.
    If you run a delta init and than a delta update then the number of the records should match with the record of the full update.
    You can find some more info about table BWOM2_TIMEST here:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/a7f2f294-0501-0010-11bb-80e0d67c3e4a#527,7,Timestamp%20Mechanism:%20New%20documents
    Bye,
         Zsolt

  • [svn:bz-trunk] 14330: BLZ-476 : Getting different error message in server' s servlet log and console log when class is not of expected type.

    Revision: 14330
    Revision: 14330
    Author:   [email protected]
    Date:     2010-02-22 10:03:03 -0800 (Mon, 22 Feb 2010)
    Log Message:
    BLZ-476 : Getting different error message in server's servlet log and console log when class is not of expected type.
    QA: no
    Doc: no
    checkin test : pass
    Ticket Links:
        http://bugs.adobe.com/jira/browse/BLZ-476
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/MessageBrokerServlet.java

    Hi, wbracken ,
    As known, there are 2 different questions I raised.
    Regarding the reply for the second one (Nothing to do with Chinese), I noticed there are several similar issues found in this forum, and it seems no response could solve my that problem. The related methods and classes were also well check, as well as the parameters put.
    Any way, your reponse was appreciated.
    Thank you for the help.

  • [svn:bz-trunk] 14341: BLZ-476 : Getting different error message in server' s servlet log and console log when class is not of expected type.

    Revision: 14341
    Revision: 14341
    Author:   [email protected]
    Date:     2010-02-22 13:19:46 -0800 (Mon, 22 Feb 2010)
    Log Message:
    BLZ-476 : Getting different error message in server's servlet log and console log when class is not of expected type.
    Ticket Links:
        http://bugs.adobe.com/jira/browse/BLZ-476
    Modified Paths:
        blazeds/trunk/modules/core/src/flex/messaging/MessageBrokerServlet.java
        blazeds/trunk/modules/core/src/flex/messaging/util/ClassUtil.java

    Hi, wbracken ,
    As known, there are 2 different questions I raised.
    Regarding the reply for the second one (Nothing to do with Chinese), I noticed there are several similar issues found in this forum, and it seems no response could solve my that problem. The related methods and classes were also well check, as well as the parameters put.
    Any way, your reponse was appreciated.
    Thank you for the help.

  • Different ways to invoke a servlet from another servlets?

    Hello,
    I am a bit confused today. I was thinking about all the ways by which I can invoke a servlet from another servlets. I know it can be done by creating an instance of the 2nd servlet in the 1st one. Is there any other way? such as say.... RequestDispatcher perhaps?
    Here is an example to illustrate my point. I have a login.jsp which submits to login.do. login.do search through database and first authenticate email and then the corresponding password. Now its time for displayGame.do. So here how do i do? if it was a displayGame.jsp then i could have used Redirection or Forward but when it is servlets? Can I still go for Redirection or Forward??
    Thank you for reading this confused post. :-)

    if it was a displayGame.jsp then i could have used Redirection or Forward but when it is servlets?Question: do you know what a JSP becomes when you first run it?
    Answer: a servlet.
    So yes, you can use a RequestDispatcher to forward/redirect to a servlet OR a JSP, whatever you like.

  • Different behaviour of j_security_check between 6.1 and 8.1

    Hi,
    we have a web-application that is secured via security-constraints in
    the web.xml. We are authenticating using FORM-based authentification and
    had this app deployed on a wls6.1. Now we have moved to 8.1 and have a
    different behaviour between 6.1 and 8.1 for log-in forms using the
    j_security_check. We have login-boxes on most pages:
    <form method="POST" action="j_security_check">
                                  Username<br><input type="text" name="j_username" size=11
    class="texteingabe"><br>
                                  Password<br><input type="password" name="j_password" size=8
    class="texteingabe"> <input type=image
    src="/dvrWebApp/htdocs/images/pfeil_rechts_hi.gif" border=0><br>
    </form>
    that on 6.1 redirected after the login to the page they were placed on -
    on 8.1 the login redirects to the root of the web-app, regardless of the
    page they are placed- can i change this back to the old 6.1-Behaviour?!
    cheers
    stf

    This sounds like bollocks, I was doing some form based security recently under 8.1 and there was no attempt to direct to any page i was not trying to access.
    The idea is you try to access a protected resource, your not authorized, so you are authenticated, then you continue on to that resource.
    Are you sure, that the resource your accessing does not direct you there because of some inbuilt business logic in your JSP/servlet ?

  • Calling a servlet from another servlet?

    Hi
    I would like to know that how can I call one Servlet from another Servlet. I have tried getServlet() method of ServletContext but it has been deprecated. I want to call a specific method of the other Servlet, is there any other way?
    Thanks

    I should have seen it from your previous post :(
    Code of Servlet 1:
    public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws
    ServletException, IOException
    RequestDispatcher rDispatch = null ;
    rDispatch = getServletConfig
    ().getServletContext().getRequestDispatcher
    ("/Servlet2") ;
    rDispatch.forward(request, response) ;
    System.out.println("Back in 1");
    I assume Servlets 1and 2 are in same web app and you've mapped your servlet2 to /Servlet2 in your web.xml
    make it as
    rDispatch = request.getRequestDispatcher("/Servlet2");
    rDispatch.forward(request,response);
    Nothin's wrong with yer servlet2

  • How to convert old Java Servlets to OSGi "Servlet" Bundles

    Hello I'm looking for some help/insight on the best way to convert some of our old Java Servlet code into new OSGi Bundles that can be accessed as servlets.  I'd like to be able to install the new bundles then access them on one of our CQ instance using something like "/servlet/servlet_name".
    So far I've been able to create a new bundle, and install it into CQ but I haven't been able to access the bundle at the servlet mapping URL that I would expect.  So far what I've found online has lead me to believe that I need to use the Felix Annotations to describe my servlet.
    @Component(immediate = true, metatype = true, label = "Servlet Name")
    @Service
    @Properties({
        @Property(name = Constants.SERVICE_DESCRIPTION, value = "Servlet Name"),
        @Property(name = "sling.servlet.methods", value={"GET"}),
        @Property(name = "sling.servlet.paths", value = "/servlet/my_servlet_mapping"),
        @Property(name = Constants.SERVICE_VENDOR, value = "VendorName")
    public class TellAFriend extends HttpServlet {...
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
    Once I have this installed, and running without an error in the logs for CQ I tried to go on my local instance to http://localhost:4502/servlet/my_servlet_mapping but I only get 404 Resource Not Found errors.  I've even gone to the Sling Resource Resolver and it doesn't resolve to anything either.
    Is there more than the Servlet Information need into the Annotations to convert "old" code into a new OSGi Servlet Mapped Bundle?

    I must be missing something else configuration wise since I created a new Servlet basically using the code you provided above.  I deployed it as part of the bundle that I'm trying to create.
    The bundle installs and stars fine but I still can't access the servlet.  Are there CRXDE based configurations that are requried too to configure Servlets. 
    Here's my test servlet file.  I tried going to http://localhost:4502/servlet/TestCQServlet and just get the same 404 error I'm getting for the other 2 Servlets Java classes in my Bundle.
    import java.io.IOException;
    import javax.servlet.ServletException;
    import org.apache.felix.scr.annotations.sling.SlingServlet;
    import org.apache.sling.api.SlingHttpServletRequest;
    import org.apache.sling.api.SlingHttpServletResponse;
    import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
    @SlingServlet(paths = "/servlet/TestCQServlet", methods = "GET")
    public class TestCQServlet extends SlingSafeMethodsServlet {
        // @Reference
        // private Repository repository;
        private static final long serialVersionUID = 6239754936223276983L;
        @Override
        protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
            response.setHeader("Content-Type", "application/json");
            response.getWriter().print("whatever");

  • Can't define init parameters for multiple servlets

    I want to define init parameters for two servlets in the web.xml file but i only get null for my Login servlet
    <web-app>
    <servlet>
    <servlet-name>
    RSServlet
    </servlet-name>
    <servlet-class>
    RoadSafe.Servlet.RSServlet
    </servlet-class>
    <init-param>
    <param-name>serverip</param-name>
    <param-value>localhost</param-value>
    </init-param>
         <load-on-startup>
              2
         </load-on-startup>
    </servlet>
         <servlet>
    <servlet-name>
    Login
    </servlet-name>
    <servlet-class>
    RoadSafe.AdMisc.Login
    </servlet-class>
    <init-param>
    <param-name>serverip2</param-name>
    <param-value>localhost</param-value>
    </init-param>
         <load-on-startup>
              1
         </load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>
    RSServlet
    </servlet-name>
    <url-pattern>
    /RSServlet
    </url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>
    Login
    </servlet-name>
    <url-pattern>
    /Login
    </url-pattern>
    </servlet-mapping>
    </web-app>

    In the code for you Login servlet, are you using the name "serverip2" to access the initial parameter ?
    Thats the name you have used in the web.xml file.

  • Servlet to Remote Servlet File Transfer

    Hey there, this is my very first post :)
    I've been surfing the forum for a solution to my problem but have had no luck so far.
    The problem is:
    I want a client to upload a file to a servlet. (easy part)
    And then i want to that servlet to upload that file to another servlet on a different server. (hard part)
    Why?
    Because we have many backup servers and test servers that have to be the same i.e contain the same images,html pages,files etc.
    And we want an easier why to synchronise them other than doing it via copy paste methods for each server... very time consuming.
    Just wondering if anyone has tried to do this?
    and
    If anyone knows of a way to transfer a file from a servlet to another servlet on a different server?
    or
    If you know an easier way to do this then servlet to servlet file transfer, your insight would be much appreciated.
    Code examples would be very helpful or relevant links.
    Thanks for you time
    dudz_josh

    use HttpUrlConnection in 1 servlet to get a connection to
    the 2 servlet.
    then 1 get OutPutStream and write file.
    in 2 get InputStream and read file
    or
    add the file object/stream to the request and forward it
    too the other servlet.
    the file is just a java object

  • Servlet Calls another Servlet, Returns an Object

    Is it possible to call another servlet (which is loaded through
              Load-on-startup) from another servlet. The return should be an Object.
              I know I am kind of asking for a procedural way of programming.
              Example : Servlet "IamReady" is loaded and gets a request with binary
              data. It replies with a Binary Object.
              Servlet "serviceCall" calls IamReady to get the resoponse.
              I know that there are forward (using requestDispatcher) and "include"
              directives to have another servlet service calling servlet.
              Also, if I define a method in the (generic servlet) does each call to
              methos is executed in different thread (like doPost and doGet).
              Thanks.
              Chris
              

    "Michael Reiche" <[email protected]> wrote in message news:<[email protected]>...
              Thank you Michael,
              > It is possible to call a servlet from a servlet.
              >
              > You can 'return' an object by putting it in the httpRequest.
              You mean httpResponse.
              >
              > The call is NOT executed in a separate thread.
              >
              > From this post (and the other post about a connection pool) - I wonder if
              > you really need to be using servlets. I couldn't think of a good reason why
              > the connection pool needs to be a servlet.
              Are you suggesting I should just have a class. Reason I have it as
              servlet, b'caz I do a load-on-startup and do initialiazation etc. in
              the init method. May be if you suggest how I can do it otherwise, I
              would like to implement it that way.
              Thanks again.
              >
              > Mike
              >
              > "MOL" <[email protected]> wrote in message
              > news:[email protected]...
              > > Is it possible to call another servlet (which is loaded through
              > > Load-on-startup) from another servlet. The return should be an Object.
              > > I know I am kind of asking for a procedural way of programming.
              > >
              > > Example : Servlet "IamReady" is loaded and gets a request with binary
              > > data. It replies with a Binary Object.
              > >
              > > Servlet "serviceCall" calls IamReady to get the resoponse.
              > >
              > > I know that there are forward (using requestDispatcher) and "include"
              > > directives to have another servlet service calling servlet.
              > >
              > > Also, if I define a method in the (generic servlet) does each call to
              > > methos is executed in different thread (like doPost and doGet).
              > >
              > > Thanks.
              > >
              > > Chris
              

  • Servlet calling another servlet in diff J2EE app

    Hi.
    Can a servlet load another servlet in different J2EE application ?
    If so, could you show me how ?
    Code example would be much appreicated.
    Thanks.

    Call the other servlet's absolute url thro' urlconnection.
    URL url=new URL("http://server:port/servlet/otherservlet");
    InputStream in=url.openConnection();
    Other servlet will be loaded. Read response if you want to.

  • Servlet as HomePage in Mie and Netscape

    Hi to all, I'm doing a java proxy that filters the webs, It consists on a servlet (with tomcat), but how can I do that every url that I write in the browser goes to http://localhost:8080/ProxyWeb I tried to do it with Internet options---> Proxy --> Url: localhost port:8080 but how can i do it? thank's.

    I got it, in the web.xml I put:
    <servlet-mapping>
    <servlet-name>ProxyServlet</servlet-name>
    <url-pattern></url-pattern>
    </servlet-mapping>
    but i have another problem, in the browser i write http://sabweb.uab.es
    and the browser send the petition throw the proxy (my servlet) and the servlet do:
    String url=request.getQueryString();
    System.out.pritnln("query is: "+url);
    and the result is null.
    I need to know the query that i wrote in the browser.

  • SQL Server Management Studio and Native Client different behaviour on delete

    I have a problem with transaction containing insert and delete to same table and some select/insert/update to some other tables. Problematic table has primary key defined as combination of column1 and column2.
    When two different instances using Native Client execute simultaneously this code and make inserts to table then delete part of code causes deadlock. However this doesn't happen when trying this situation in MS SQL Server Management Studio query.
    Is there some option that is missing from Native Client connection string which can cause this different behaviour?

    Hello,
    I don't think there is a difference in the behavior. SSMS uses ADO.NET and that Provider base on the Native Client.
    The difference will be more that way, when the transaction is commited and so the locks released. I guess your application keeps the transaction (much) longer open; you should commit a transaction as soon as possible to avoid long time locks and so
    deadlocks.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

Maybe you are looking for

  • Forms and validations - here's some of my ideas, what are yours?

    One of the big things still missing from the JFX space (especially where JEE is concerned) is forms and form validations. Maybe you guys have been luckier but at least 80% of the screens I've had to build in my career have been boring old forms - ent

  • Material Determination based on Availability

    Hi SD gurus, I have a client requirement as below: We create order via BAPI. Data comes from ext call center system. Whenever Matnr A is entered in Sales order & it is not available then Matnr B should come. 1: I know that we can handle this in Mater

  • Bind variable code takes more time to complete?

    Hello, My database is oracle11g. I have same plsql code and first one is without bind variable and second one is with bind variable. Usually, bind variable should take less time. But here the bind variable takes more time than the regular code... Can

  • How can i get a new casing (skin) for my iphone?

    how do i get a new skin case thingy? because my white iphone condition isnt the best. want it new again

  • Quicktime Presets Disappeared?

    Is it my imagination, or have most of the Quicktime codecs disappeared from my Export dialogue box?: Dropbox - Screenshot 2014-07-28 17.17.55.png If that's the case, is there anyone who could give me advice as how to get them back? Thanks.