Mapping webapp URLs to a single servlet which forwards to JSP

I am using JSP for page presentation, but I want to have all requests
          intercepted by a servlet, which will perform various functions before
          forwarding to the requested JSP page. In general, I want the URL to
          reflect the target JSP page, to facilitate bookmarking. I'm using a
          web application to deploy the servlet+JSPs.
          Ideally, I wanted to have all request URLs look like a request for the
          JSP page without the .jsp extension (so
          http://hostname/webapp/here/there maps to /here/there.jsp within
          webapp). However, I can find no provision in web.xml for mapping all
          URLs without extensions to a specific servlet. I can use '/' to map
          all requests to the servlet, but then even image or HTML requests
          get intercepted (and trashed).
          On the other hand, if I map '*.jsp' to the servlet, then when I try to
          forward to the actual JSP page, the servlet gets invoked again
          recursively.
          I could create an arbitrary extension and map it to the servlet, and
          then have the servlet replace my custom extension with '.jsp' before
          forwarding, but this seems a bit funky.
          Has anyone come up with a better solution to this, within the context
          of a webapp? Seems like it should be a not-uncommon scenario.
          Thanks,
                              -- Peter
          

Yes, you can! It depends on how you access the servlet. If you access it via GET method you must add a request parameter to the url to distinguish from which jsp the request comes. If you use POST method (with form submission) put a hidden field in the form and with that field you can recognize from which jsp the request comes.
Message was edited by:
amittev

Similar Messages

  • Mapping an url-pattern to a servlet in a hosted environment

    This may not be exactly the right place for this, but I thought someone may have had similar experiences and be able to suggest something...
    My JSP/Servlet application runs fine in a Tomcat -standalone environment, however there are certain mappings (hrefs and what-not) that do not function when I upload it to the hosted environment I am using. For example, the index page contains a link to something like /xyz. /xyz is an url-pattern specified in my web.xml that is then mapped to a servlet. The hosted application gets an Apache 404 when following such a link, because (the hosting help desk tell me) by default the only requests that Apache forwards to Tomcat are /*.jsp, /*.xml and /servlet/*, as defined in their httpd.conf.
    Are any of the following possible?
    1. They introduce somes line into the Tomcat section of their httpd.conf forwarding requests like myHostedSite/xyz to my instance of Tomcat (and so not forwarding theirOtherHostedSites/xyz).
    2. (My preferred shot-in-the-dark) They introduce a line into their httpd.conf that, for my site, then references another configuration file (on my part of the system), in which I could maintain a list of mappings that Apache should forward to Tomcat.
    Otherwise, I guess, I am left to change all refences in my code and pages from /xyz to /servlet/xyz which is ugly and feels like a kludge.
    Any hints, tips, help or advice (or even directions to a better place to post this) gratefully received.

    For Point 2, surely they are using a Virtual Host for your app on tomcat? this means they should be able to configure ALL requests to Tomcat based on your Virtual Host. Unless of course your using thier host name and utilising only the context path???
    The httpd.conf should have something like:<VirtualHost your.domainName.com:80>
        ServerAdmin [email protected]
        DocumentRoot /path/to/your/app
        ServerName your.domainName.org
        ErrorLog /path/to/error/log
        CustomLog /path/to/custom/log
        JkMount /*.jsp worker1 //your worker.properties file
        JkMount /*.html worker1 //your worker.properties file
    </VirtualHost>With the DocumentRoot set it should default all your gifs, jpegs etc but route htmls, jsps and servlets through to your tomcat instance as configured with your worker.properties file.
    I have to admit, Apache to Tomcat integration can be a nightmare and the Apache httpd.conf file is a monster but the above code should work provided you have yout own domain name.
    Regards,
    Anthony

  • Can a single servlet process 2 diffrent jsp pages?

    I am kinda new to the jsp world. Here is the question i have.
    I have 2 jsp pages and a sigle servlet class. Both the jsp pages need to be processed by the same servlet. The servlet needs to run diffrent logics based on which jsp the request is being sent from. Is there any way for the servlet to know which jsp the request is coming from( like having an attribute in the form tag of the jsp which the servlet can later retrieve)?
    I am using only jsp's and servlet( not using any other technology like struts or JSf's). I appreciate any kind of help. Thank you.

    Yes, you can! It depends on how you access the servlet. If you access it via GET method you must add a request parameter to the url to distinguish from which jsp the request comes. If you use POST method (with form submission) put a hidden field in the form and with that field you can recognize from which jsp the request comes.
    Message was edited by:
    amittev

  • How to Create an XML document from XSQL servlet which follows a particular DTD struct

    how to Create an XML document from XSQL servlet which follows a particular DTD structure.Could anyone send me a sample code for this.

    You'll need to associate an XSLT transformation with your XSQL page that transforms the canonical result into your DTD-valid format.
    For example, given an XSQL page like:
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="rss.xsl" ?>
    <xsql:query max-rows="3" connection="demo" xmlns:xsql="urn:oracle-xsql">
    select title,id,description,url,to_char(timestamp,'Mon DD') timestamp
    from site_entry
    order by id desc
    </xsql:query>and an "rss.xsl" stylesheet that looks like this:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" doctype-system="rss-0.91.dtd"/>
    <xsl:template match="/">
    <xsl:for-each select="ROWSET/ROW">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    <xsl:for-each select="ITEM">
    <item>
    <title><xsl:value-of select="TITLE"/></title>
    <link><xsl:value-of select="URL"/></link>
    <description><xsl:value-of select="DESCRIPTION"/></description>
    </item>
    </xsl:for-each>
    </channel>
    </rss>
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>You produce DTD-valid output against the rss-0.91.dtd DTD that looks like:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <!DOCTYPE rss SYSTEM "rss-0.91.dtd">
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>
    <rss version="0.91">
    <channel>
    <title>Do You XML?</title>
    <link>http://xml.us.oracle.com</link>
    <description>Oracle XML Website Demo</description>
    <language>en-us</language>
    </channel>
    </rss>

  • How to get response from a servlet which depends on cookies?

    guys,
    i have a servlet which behaves differently based on the presence of a cookie or not. If cookie A is present in the machine it shows the the home page and if not it shows the login page.
    now i want to get the home page HTML content from a program without using the browser. i am aware this can be done by using java.net.URL but how do i simulate the cookie given that i know that's the cookie name and value it expects?
    Unfortunately i cannot paste the servlet code as it is a servlet of a product and i don't have the source code for it.
    Thanks
    S

    I believe you use URLConnection.setRequestProperty(), with the key being "Cookie".

  • Different url-patterns for same servlet running in 2 different environments

    Hi All,
    I have a question about url mappings in my web.xml file and I hope somebody can help. The situation is that I�m putting together a web app using a combination of JSPs and servlets. I can�t develop on the machine that it will be hosted on, so I�m working and testing on my own machine and will transfer to the host machine when finished. However, the host machine is set up to map serlvets to http://�/servlet/MyServlet but the copy of tomcat I have installed locally maps to http://�/MySerlvet. My question is, when I get ready to transfer my application do I have to go through all my code and find serlvet references and insert the �servlet/� path info required by the hosting service, or can I just change the url patterns for the servlet mappings of the web.xml file on the host machine ? In other words:
    Local install of Tomcat where servlets are accessed at http://�/MyServlet
    <servlet-mapping>
    <servlet-name> MyServlet </servlet-name>
    <url-pattern>/MyServlet </url-pattern>
    </servlet-mapping>
    Host machine install of Tomcat where servlets are accessed at http://�/servlet/MyServlet
    <servlet-mapping>
    <servlet-name> MyServlet </servlet-name>
    <url-pattern>/servlet/MyServlet </url-pattern>
    </servlet-mapping>
    I guess my thinking is that it would be better/easier to have a remote and local version of the web.xml file that reflects the environment each one resides in and have only one codebase rather than 2 codebases and 1 web.xml file. Am I thinking about this in the right way, or have I misunderstood something?
    Thanks,
    Peter

    What you�re suggesting is logical, but won�t that
    effect all the other stuff I�ve got running on my
    local Tomcat install that expects servlets to be
    accessed at http://.../ServletName ?
    in web.xml, you decide of your mapping, so you could use the /servlet/ServletName pattern for your application that needs to be remote, and /ServletName for the rest of your stuff. You can even define more than one mapping for a servlet...
    In fact, you should probably put your whole application that is going to be on a remote server in it's own context, and to be ahead of dufymo :-) , learn to put it a war file for deployment.

  • Taking in many concurrent requests via a single servlet

    Hi,
    My objective for this topic is to find a way to make my tomcat app able to handle as many as possible concurrent requests.
    My app spec is
    -servlet running on Tomcat 5.0
    My app is a mobile text messaging app that receives requests via a single servlet, called InboundRequest. This servlet will,
    1. Read the HTTP params in the request
    2. Decide to which other servlet classes it should forward to (RequestDispatcher)
    3. The recipient servlet will read the HTTP param, process it and outputs the data via OutboundResponse java class.
    So, my issue is,
    1. What factor decides the number of concurrent requests my InboundRequest servlet can handle? Is it my code or Tomcat itself or the server hardware
    2. Since I'm using Request Dispatcher forwarding, if say i have a request that takes 5 seconds to complete the its task (to output the result via OutboundResponse), will in inhibits/stops any other requests that comes in during that 5 seconds?
    I appreciate all expertise i can get.
    Regards,
    Mel.

    There is nothing to worry about that concurrent request handling as container will create one instance of your servlet and then for each client request it will spwan a single thread which will handel the client request.If u r implementing SingleThreadModel then onle one thread will be spwan and it will handle the requests one by one .So it will be slower .

  • Lync 2013 webapp URL asking credentials when accessing from web-browser

    Hi,  when I tried to access Lync2013 Webapp URL , I am being asked for asked enter credentials to display options to join meetings.
    screenshot attached...

    Hi,
    Which Website Browser did you use?
    Did the issue happen only for you or for multiple users?
    Please test on other computer.
    Please double check anonymous access settings and conference policies, make sure “enable anonymous user access to conferences” enabled.
    Best Regards,
    Eason Huang
    Eason Huang
    TechNet Community Support

  • Determine an URL from an identifier (servlet name, jsp name or something)

    I would like to write URLs in my JSP files, but I don't want to hardcode them. Is any way to use the datas from the web.xml?
    So I would write the name of the Servlet / name of the JSP file and it would resolve to an URL.
    Is any method for this?
    Very thanks your help!

    The server will load the properties file into memory so there will be some memory overhead. The actual amount of memory used will be server dependent. If you want to make sure the file is loaded just once and the data cached for the entire application set the scope in the fmt:setBundle tag to application. This means the file will be loaded once and stored in memory. The cache will be maintained for the life of the application.
    If you want to free memory when the the properties aren't needed, then you can set the scope in the fmt:setBundle tag to page (the default), which will allow (but not force) the memory used by the cache to be released when memory is low.
    Note that there are 2 scopes at play here, the properties file is loaded and cached in the resource-loading process so the file would only need to be re-loaded when the data changed. The second is the scope the bundle is stored in for the web application. As long as the web application holds the bundle, the resource cache will not be freed. When the reference is released by the web application the cache may be released if memory requires it, or may be kept so the next time the resource is needed there isn't an overhead related to loading the bundle again.
    Setting the scope in the fmt:setBundle to page is the most flexible use, because it allows the Resource cache to hold the properties file in memory then just provide references as needed (much like if you had the scope set to application), but also allows the cache to be free its memory if required.
    In the particular example provided above, you don't have control of the Resource Caching. You could implement your own implementation of a ResourceBundle and use ResourceBundle.Control to configure the Cache. This could be done invisibly behind the scenes if you find the memory used by the default implementation too much.

  • How can I display the HTML page from servlet which is called by an applet

    How can I display the HTML page from servlet which is called by an
    applet using the doPost method. If I print the response i can able to see the html document. How I can display it in the browser.
    I am calling my struts action class from the applet. I want to show the response in the same browser.
    Code samples will be appreciated.

    hi
    I got one way for this .
    call a javascript in showDocument() to submit the form

  • Calling 3 different servlets from a single servlet

    hi all,
    i am in lot of soup...i am new to servlets,etc....so help me pls.
    i need to call 3 different servlets from one servlet. all 3 servlets that i want to call perform different functions and execute queries on the database.
    what i am trying to do is:
    there is an html page that call a servlet called authenticate.java.(whose code is at the bottom of this page).
    the servlet authenticate.java should authenticate a user according to the password and username supplied in the html page.
    MAINLY:-
    i need to display 3 buttons to the authenticted user. those 3 buttons each should call 3 different servlets, which do different things.
    now in authenticte.java i set certain information in the session using session.putValue();
    further, whatever servlet is called, i need to use that information i set into the session...using session.getValue().
    PLS TELL ME HOW TO DO THAT...ALSO C IF THE BELOW CODE IS OK.
    ALSO TELL ME HOW TO END A SESSION. ALSO DO SERVLETS SUPPORT SESSIONS?
    I AM USING jdk1.3 and jsdk2.0.
    * Authenticate.java
    // this places all user variables in session
    //to access use session.getAttribute
    //dispatcher stuff
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.http.HttpSession;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    * @author Gudiya
    * @version
    public class Authenticate extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    HttpSession session = request.getSession(true);
    Connection con=null;
    String sessionid;
    String deptcode;
    String desig;
    String add1;
    String add2;
    String contname;
    PrintWriter out = response.getWriter();
    try
    {System.out.println(1);
    response.setContentType("text/html");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:SACFA","","");
    System.out.println("connection established");
    catch(ClassNotFoundException e){
    System.out.println("database driver not found");
    System.out.println(e.toString());
    catch(Exception e){System.out.println(e.toString());
    String username=request.getParameter("username");
    String password=request.getParameter("password");
    try{
    System.out.println(2);
    PreparedStatement stmt=con.prepareStatement("SELECT * FROM AUTHENTICATION,mb_add where AUTHENTICATION.NAME=? AND AUTHENTICATION.PASSWORD=? AND mb_add.DEPT_NAME=?");
    stmt.setString(1,username);
    stmt.setString(2,password);
    stmt.setString(3,username);
    ResultSet rs=stmt.executeQuery();
    System.out.println(3);
    boolean rowfound=false;
    rowfound=rs.next();
    if (rowfound==true)
    sessionid=session.getId();
    System.out.println(sessionid);
    System.out.println(4);
    session.putValue("user",username);
    rs.beforeFirst();
    while (rs.next())
    System.out.println(5);
    deptcode=rs.getString("DEPT_CODE");
    desig=rs.getString("DESIGNATION");
    add1=rs.getString("ADDRESS1");
    add2=rs.getString("ADDRESS2");
    contname=rs.getString("NAME");
    session.putValue("dept_code",deptcode);
    session.putValue("designation",desig);
    session.putValue("address1",add1);
    session.putValue("address2",add2);
    session.putValue("cont_name",contname);
    System.out.println(6);
    }          out.println("<html>");
              out.println("<head>");
              out.println("<title>Successful Login Screen</title>");
              out.println("</head>");
              out.println("<body bgcolor='ORANGE'>");
    out.println("WELCOME SACFA MEMBERS FROM "+ username);
    //print decorative html statements here
              out.println(" SELECT ANY ONE ACTION:-");
    //out.println("<form Action="+"\"servlet/noc\""+" method =post>");//call for your noc servlet
    //print decorative html statements here
    out.println("<INPUT TYPE=submit VALUE='GENERATE NOC' NAME='NOC'>");
    out.println("</form>");
    //print decorative html statements here
    //out.println("<form Action="+"\"servlet/comments\""+" method =post>");//call for your comment servlet
    out.println("<INPUT TYPE=submit VALUE='ENTER/ MODIFY COMMENTS' NAME='COMMENTS' >");
    out.println("</form>");
    //print decorative html statements here
    // out.println("<form Action="+"\"servlet/bye\""+" method = post>");
    out.println("<INPUT TYPE=submit VALUE=EXIT NAME=EXIT >"); //place javascript fucction for exiting window
    out.println("</form>");
              out.println("</body>");
              out.println("</html>");
    con.close();
    } catch( SQLException e){ }
    out.close();}
    THANK YOU,
    REGARDS,
    ASHNA

    Hi Ashna,
    You have use three different forms for three buttons. But I think all are commented one.It will also work if you uncomment it.
    Else you can use only one Form without giving action in form tag. Use normal buttons instead of submit type buttons & call different JavaScript functions on onClick event for each button.
    Try this out.
    Ajay

  • I downloaded Safari 5.1 onto Mac OS 10.6.8 some time ago.  Yesterday the back/forward arrows next to the url window changed to a  , which adds the current url as a bookmark.  I want the arrows back.  What happened, and how can I fix this?  Thanks.  kammro

    I downloaded Safari 5.1 onto Mac OS 10.6.8 some time ago.  Yesterday the back/forward arrows next to the url window changed to a +, which adds the current url as a bookmark.  I want the arrows back.  What happened, and how can I fix this?  Thanks.  kammro

    There's another way.
    Right or control click the + then click Remove Item.
    Just remembered that keyboard shortcut!
    You're welcome 

  • HT4913 Hi, I was trying add a second computer on iTunes Match. I was signed into both machines with a single ID which already has iTunes Match. When I selected iTunes match, it asked me to buy it again rather than add. Now I've got it on neither machine-

    Hi, I was trying add a second computer on iTunes Match.
    I was signed into iTunes on both machines with a single ID which already has iTunes Match from the primary machine. When I selected iTunes match on the second, it asked me to subscribe to it again rather than add.
    To try to fix this, I signed out of the primary machine and so i was only in the second computer.  This didnt work and when i tried to log back into Match on the primary machine it has the same problem now, asking me to buy iTunes Match when I already have it!
    Now I've got it on neither machine- can someone please help!!
    Cheers,

    wandererny wrote:
    Only one library can be matched at a time. If you continue, the other iTunes Match session will be stopped and this computer's library will be matched instead.
    Hi,
    You often get this message when match thinks that you already have a match in progess on another computer.
    If you are happy that all your music is on your new hard drive (or if it is only in the cloud), you should select "this computer".
    Jim

  • Safari is now opening with multiple windows. Not sure what changed in my settings. I prefer Safari to open with a single homepage, which I've always set to Yahoo. Any help?

    Safari is has begun opening with multiple windows. Not sure how this change happened. I prefer Safari to open with a single homepage, which I've always set to Yahoo. Any suggestions?

    Quit the application. Force quit if necessary.
    Relaunch it by holding down the shift key and clicking its icon in the Dock. From the menu bar, select
    Safari ▹ Preferences... ▹ General ▹ New windows open with: Homepage

  • Calling a bean in weblogic 4.5 from a servlet which is in Iplanet webserver4.1

    while Calling a bean in weblogic 4.5 from a servlet which is in Iplanet webserver4.1 sometimes the servlet is not able to call the bean. There is no error logged in webserver. This is happening very rarely and when it happens I have to shut and restart IplanetWS.
    Can anyone tell me some solution or reason
    Regards
    Nitin

    We did receive a 4.5.1 / 5.1 interoperability patch - but it wasn't quite 'seamless'.
    We never tried to use it.
    SOAP? Isn't that around 50 times slower than RMI?
    Mike
    "Gary Mui" <[email protected]> wrote:
    We ran into this issue last fall and got some feedback from weblogic
    support. They originally said that it could be done (as well as different
    versions talking to one another via JMS) but it turned out that they
    were
    incorrect and ended up saying that it is not possible. Before 6.0 went
    GA,
    BEA said that there would be a interoperability patch to do this, but
    I've
    never seen nor heard of anything regarding it. As a workaround, we
    implemented 4.5.1 / 6.0 communication via SOAP.
    Mike Reiche wrote in message <3b1bcaec$[email protected]>...
    I have the same question - and more. Last year we were told that wecould
    not use
    RMI (and ejbs) between 4.5.1 and 5.1. Which seems kinda weird becauseI've
    heard
    of people using WL ejbs from Tomcat. This issue has caused us to avoidusing
    WL ejbs in any future development which has any chance of ever beingused
    by any
    app server (WL included) that is not under the direct control of thedata
    center.
    I've been trying to convince the Architecture team here that we canuse WL
    EJBs
    and we can call them from other app servers - but can't seem to getany
    supporting
    statement from BEA (maybe I haven't tried hard enough).
    Anyway, a response from BEA would be appreciated.
    - Mike
    "Madhu K" <[email protected]> wrote:
    Is it possible to call a (stateless session) bean deployed in weblogic
    6.0
    from a bean in weblogic 5.1? I have two versions of weblogic running
    on two
    different hosts and I have to call a bean that is running in 6.0 from
    5.1.
    Are there any limitations?
    Appreciate any feedback/suggestions.
    Thanks,
    Madhu

Maybe you are looking for

  • IMac died, how do I get data off Time Machine to new iMac

    My sisters iMac has had HD problems in the past - we replaced hd at Apple in the past.  I am unable to start the computer up again to look into anything. It was apparently sending out a lot of error messages, the main one being the HD was out of spac

  • Movies from ipod touch to ipad2

    I can't figure out how to get my movies bought off itunes to my ipod touch to icloud to my ipad 2. I can get my music and tv shows through the tab in itunes downloads,but can't find my movies to cloud from itunes. HELPPPP

  • FBRA performace problem

    Dear GURUs While running TCODE FBRA it is taking long time due to lots off record is available in table BKORM, The solution is delete all records from BKORM through F.63, is there any effect if we delete all record from Table BKORM. By which T. code

  • NAP on 2008 R2 with DirectAccess 2012 RC

    I'm running IPsec NAP on two indentically configured Windows 2008 R2 servers that are also standalone CAs for NAP. I'm in the testing phases of a Windows 2012 RC DirectAccess server that is behind a NAT. Certificates from our domain CA (not the stand

  • Long duration time extraction BKPF table

    I have access to SAP R/3 on a Oracle database. For one object GL Open Items I need to extract all required data from 2 tables BSIS and BKPF. (=select all open items of required G/L Accounts) Selection Criteria as follows: step 1:Select BSIS records o