MUST I include every servlet in web.xml??

I am learning servlet and trying to write some codes by myself.
When I want to invoke servlet by form, tomcat always shows that the requested resource is not available.
I've tried some different paths for the value of ACTION, but none of them work.
Hence, I'm wondering whether I can invoke a servlet in form without explicitly write it in web.xml??
Could anyone generously give me an answer?

It may be possible to configure your web server so it executes servlets with URLs like http://the.ser.ver/servlet/com.yourcompany.yourpackage.TheServlet. URLs like that are ugly and can lead to security problems so I definitely recommend against them.
You could write a front controller servlet. Then you'll need to configure the servlets in YourFrontControllerServletConfig.xml instead of web.xml so I'm not sure if that buys you much.
I'd just configure servlets in web.xml. That's what it is there for.
When you write a servlet you gather requirement specs for your servlet, do architecture and technical design, graphic layout design, servlet programming, back end code programming, unit testing, jar deployment, system (& performance, security, usability, etc) testing. After all that, the task of copy&pasting ten lines in web.xml shouldn't be a terribly large task. Unless you have lost nine of your fingers in a horrible chain saw accident or something.
(Apologies to anyone out there who has lost nine of his fingers in a terrible chain saw accident.)

Similar Messages

  • How to set two different welcome-file to different servlets in web.xml

    Hi friends,
    Can some one help with web.xml file
    I have to different servlets in applications.
    I want to set two different welcome files for my two different
    servlets in web.xml
    Please, can some one give me sample code to achieve this.
    Here web.xml code:
    <?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>reports</servlet-name>
              <servlet-class>com.caremark.ivr.servlet.IvrReportsServlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>reports</servlet-name>
              <url-pattern>/reports</url-pattern>
         </servlet-mapping>
         <session-config>
              <session-timeout>30</session-timeout>
         </session-config>
         <welcome-file-list>
              <welcome-file>reportsindex.jsp</welcome-file>
         </welcome-file-list>
         <servlet>
              <servlet-name>calldetails</servlet-name>
              <servlet-class>com.caremark.ivr.servlet.IvrCallDetailsServlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>calldetails</servlet-name>
              <url-pattern>/calldetails</url-pattern>
         </servlet-mapping>
    <welcome-file-list>
              <welcome-file>calldetailsindex.jsp</welcome-file>
         </welcome-file-list>
    </web-app>
    I need this fix immediately. Your help will be really appreciated. Thanks in advance.

    First of all, my understanding is that you need to have a Servlet 2.4 complaint server to do this...Given that, you're supposed to be able to simply specify the Name of the servlet as the welcome-file to get it to work. For example:
    Your servlet section:
    <servlet>
      <servlet-name>Controller</servlet-name>
      <servlet-class>com.company.ControllerServlet</servlet-class>
    </servlet>Now you would add the following to your welcome file list:
    <welcome-file-list>
      <welcome-file>Controller</welcome-file>
    </welcome-file-list>Note that you use the servlet-name value from the servlet definition, NOT the url-mapping from the servlet-mapping section.
    Please note that I cannot verify this as I am running a 2.3 server at home. When I get to work Friday I can test on a 2.4 machine. However this shouldn't take you more than a minute to test.
    Note that I did try this on the 2.3 compliant server and it did NOT work (as I expected)...
    HTH.

  • Do I have to register all *.jsp servlets in web.xml?

    All,
    I'm hoping someone in this forum can help me. I'm working on a report generator that uses JSP to generate a template which is fed to a formatter. What I want is to programatically call the JSP without having to add an entry for every single report to my web.xml. As you can imagine this doesn't scale well since every time a new type of report is added, someone has to go edit the web.xml.
    The options I can think of:
    1) Pre-compile the JSP's
    2) Have a servlet mapping where *.jsp "does the right thing" for me
    3) ?
    Any suggestions? I'm not sure which is the best/practical approach. I really want to get away from having to modify the web.xml for every single type of report that I can generate.
    Thanks!!
    -Javier Delgadillo
    Message was edited by:
    javidel

    Our web app is a web service where all requests get processed by an XFire servlet. So just adding the jsp on the disk somewhere won't do the trick. I have to register the jsp's.
    Is there a better way to do this?
    -Javier

  • Servlets within web.xml

              I am using WLS 5.1.0 with SP6.
              Previously I was controlling servlet access via an ACL in the weblogic.properties file.
              I have now moved the servlet into the web.xml file and specified
              some security constraints on this servlet. I can access the servlet. However regardless of what type of security I specify I cannot control access of the server by anything other than the guest user. Here is the web.xml file I have been using.
              <servlet>
              <servlet-name>AuthServlet</servlet-name>
              <servlet-class>com.myapp.web.servlet.AuthServlet</servlet-class>
              </servlet>
              <servlet-mapping>
              <servlet-name>AuthServlet</servlet-name>
              <url-pattern>auth</url-pattern>
              </servlet-mapping>
              <security-constraint>
                   <web-resource-collection>
                        <web-resource-name>Test Deployment Descriptor</web-resource-name>
                        <description>Test Deployment Descriptor for test Authentication Servlet.</description>
                        <url-pattern>/cam/auth</url-pattern>
                        <http-method>GET</http-method>          
                        <http-method>POST</http-method>
                   </web-resource-collection>
                   <auth-constraint>
                        <role-name>MarkEngstrom</role-name>
                   </auth-constraint>
                   <user-data-constraint>
                        <transport-guarantee>NONE</transport-guarantee>
                   </user-data-constraint>
              </security-constraint>
              <login-config>
                   <auth-method>FORM</auth-method>
                   <realm-name>default</realm-name>
              <form-login-config>
                        <form-login-page>/form.jsp</form-login-page>
                        <form-error-page>/error.jsp</form-error-page>
                   </form-login-config>
              </login-config>
              Note : the <role-name> is a user I have specified in my weblogic.properties file. I am using the default security realm.
              I don't get any exceptions reported in the log files and I think it must be some configuration I have missed because the security constraints appear to be totally ignored.
              Does anyone have any suggestions ?.
              Thanks,
              Mark Engstrom
              

              hi, I pump to the same problem before.
              I think you url mapping when you define web resource should starts with /, or
              you say url pattern to be *
              Good luck
              "MarkE" <[email protected]> wrote:
              >
              >
              >I am using WLS 5.1.0 with SP6.
              >Previously I was controlling servlet access via an ACL in the weblogic.properties
              >file.
              >
              >I have now moved the servlet into the web.xml file and specified
              >some security constraints on this servlet. I can access the servlet.
              >However regardless of what type of security I specify I cannot control
              >access of the server by anything other than the guest user. Here is
              >the web.xml file I have been using.
              >
              > <servlet>
              > <servlet-name>AuthServlet</servlet-name>
              > <servlet-class>com.myapp.web.servlet.AuthServlet</servlet-class>
              > </servlet>
              >
              > <servlet-mapping>
              > <servlet-name>AuthServlet</servlet-name>
              > <url-pattern>auth</url-pattern>
              > </servlet-mapping>
              >
              > <security-constraint>
              >      <web-resource-collection>
              >          <web-resource-name>Test Deployment Descriptor</web-resource-name>
              >          <description>Test Deployment Descriptor for test Authentication Servlet.</description>
              >          <url-pattern>/cam/auth</url-pattern>
              >          <http-method>GET</http-method>          
              >          <http-method>POST</http-method>
              >     </web-resource-collection>
              >     <auth-constraint>
              >          <role-name>MarkEngstrom</role-name>
              >     </auth-constraint>
              >     <user-data-constraint>
              >          <transport-guarantee>NONE</transport-guarantee>
              >     </user-data-constraint>
              > </security-constraint>
              >
              > <login-config>
              >      <auth-method>FORM</auth-method>
              >     <realm-name>default</realm-name>
              > <form-login-config>
              >           <form-login-page>/form.jsp</form-login-page>
              >           <form-error-page>/error.jsp</form-error-page>
              >      </form-login-config>
              > </login-config>
              >
              >Note : the <role-name> is a user I have specified in my weblogic.properties
              >file. I am using the default security realm.
              >
              >I don't get any exceptions reported in the log files and I think it must
              >be some configuration I have missed because the security constraints
              >appear to be totally ignored.
              >
              >Does anyone have any suggestions ?.
              >
              >Thanks,
              >
              >Mark Engstrom
              >
              

  • Eclipse, WTP, Servlets and Web.xml

    I wonder if you could help me.
    I am using Eclipse and Web Tools Platform.
    In eclipse, when I create a Servlet, I believe the servlet details (such as name, class, url-pattern) should be included into web.xml file automatically. However, this is not happening.
    Would you know how I can configure Eclipse and WTP to automatically write Servlets details into web.xml files.
    Thanls

    Thanks for the reply
    I have Eclipse 3.2 and WTP 1.5
    Yes, I am creating my Servlet in a project under the Dynamic Web Projects.
    I deploy my WAR file using the 'Export' menu.
    Now, I have manually added the servlet details into the web.xml file:
    <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>com.mycom.HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>/HelloWorld</url-pattern>
    </servlet-mapping>
    I am accessing the servlet as:
    http://localhost:9090/MyFirstServlet/HelloWorld
    But I still get HTTP 404 error when accessign HelloWorld servlet. I am not sure what I am missing.
    Thanks

  • Help needed in Mapping servlet in web.xml file

    Hi Can anyone please tell me what am doing wrong here. I can't see this servlet in my url. Please help.
    <servlet>
    <servlet-name>HelloWorld</servlet-name>
         <servlet-class>HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>/com/jci/fi/application/eems/HelloWorld/*</url-pattern>
    </servlet-mapping>
    package com.jci.fi.application.eems;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloWorld extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<body>");
    out.println("<head>");
    out.println("<title>Naveen Wants to goto TollyWood......!</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Hello World!</h1>");
    out.println("</body>");
    out.println("</html>");

    your web.xml shoould be something like this...
    <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>com.jci.fi.application.eems.HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>HelloWorld</url-pattern>
    </servlet-mapping>
    Hope this helps..
    CK

  • Registered servlets in web.xml do not work....WHY????

    Hi i am executing a web application on tomcat 4.1.29 and have the following structure...the jsp pages are executed but when sendinga request to a servlet the servlets are not executed...Can somebody guide me out of this....
    webapps
    {MyApp}->[web-inf][jsp]
    {web-inf}->[classes][lib]
    {classes}->[com][src]
    {src}->[source files]
    when the source files are compiled package structure is followed and the class files are grneated in
    com.MyApp.servlets
    ...etc
    the servlets are registered in the web.xml file as shown below.....few lines of my web.xml file
    <servlet>
    <servlet-name>userServlet</servlet-name>
    <servlet-class>com.MyApp.servlets.UserServlet</servlet-class>
    </servlet>
    even then when accessing a servlet it says the resource not found
    The requested resource (/MyApp/servlet/UserServlet) is not available.
    am i missing something some where...why are the servlets not executed????

        <servlet>
            <servlet-name>UserServlet</servlet-name>
            <servlet-class>com.MyApp.servlets.UserServlet</servlet-class>
            <load-on-startup>2</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>UserServlet</servlet-name>
            <url-pattern>/User</url-pattern>
        </servlet-mapping>I'd invoke it with this URL:
    http://localhost:8080/MyApp/UserServlet
    hmm something seems to be wrong here ;-)
    URL should be
    http://localhost:8080/MyApp/User (see <url-pattern>)

  • Can two urls map to same servlet in web.xml

    Hello All,
    I need to map the two urls in my web application with the same servlet.
    I tried as follows:
    <web-app 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" xmlns="http://java.sun.com/xml/ns/j2ee">
    <description>Empty web.xml file for Web Application</description>
    <servlet>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>fileredirectsolution.TestServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/testservlet</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>/filerepository/*</url-pattern>
    </servlet-mapping>
    </web-app>
    However, I am getting an error while accessing the TestServlet.
    When I remove the second servlet-mapping tag..it is working fine.
    How can I map the two urls with the same servlet.
    Thanks
    Saikrishna

    it is not ur requirement. but
    i think it will help 2 u.
    <web-app 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"; xmlns="http://java.sun.com/xml/ns/j2ee">
    <description>Empty web.xml file for Web Application</description>
    <servlet>
    <servlet-name>TestServlet</servlet-name>
    <servlet-class>fileredirectsolution.TestServlet<;/servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>TestServlet</servlet-name>
    <url-pattern>*.xxx</url-pattern>
    </servlet-mapping>
    </web-app>
    if ur configure web.xml like above.
    any request that ends with .xxx call the TestServlet.
    ex:
    1)http://ip:port/contextpath/abc.xxx
    2) http://ip:port/contextpath/xyz.xxx
    here both urls calls the same servlet.
    -lakshman.
    save a life by sending information.
    www.help2patients.wordpress.com.

  • Configuring the web.xml to run Servlets

    Hi,
    Can i get some help to configure my web.xml file... ?
    I am trying to run servlets. Do i need to map each servlet i use or can i just create a folder and map the folder. Which web.xml file do i need to change... ? And under which directory shall i place the servlet folder.
    Thanks

    Hi,
    which server ur using ? if its tomcat then this can help u out..
    u have to change the web.xml file in ur own directory.
    for example u have ur directory in tomcat/webapps/<ur directory>
    then in ur directory u have to create 1 WEB-INF directory and copy the web.xml file in that. another thing u have to make 2 direcotries in WEB-INF.
    one is classes - u can keep ur servlets class files + ResourceProperty file
    second is lib - u can keep the library files here
    and u have to register ur each and every servlet in web.xml file
    take care
    enjoy the coading
    kedar

  • When to specify taglib uri in web.xml

    When declaring a URI in the taglib directive, when must you include the taglib elements in web.xml, and when can you avoid them?
    I tried putting a relative path to the .tld file, setting uri to �/WEB-INF/mysubfolder/myfile.tld�, but my web server complains that I�m missing a tlib-version element somewhere�
    What is the uri path relative to, and in what cases must you include a mapping in web.xml and when do you not have to?
    Thanks.

    So it sounds like your tld file has some invalid xml in it.
    Double check the contents of your tld file.
    If you declare a <uri> in your taglibrary, then you never need to declare it in web.xml.
    You can just use that "well-known" uri to access your tag library.
    The tld has to be either
    1 - in the META-INF folder of a jar file deployed
    2 - under the WEB-INF directory
    See JSP specification section JSP.7.3.1

  • Web.xml question

    Hi Guys!
    I ran into a small problem.
    Im using the struts tiles framework to redesign a shopping cart .
    In the new framework,there are multiple websites(user interface tiles) that use the same servlets at the back end to process the requests. The control is passed back to the website that called the commonly shared servlets once the computations are done.The servlets, the various websites that use the servlets all reside on the same server and are a part of the same project.
    The whole project shares a common web.xml file.
    I was just wondering if each of the tiles can have thier own web.xml so that the servlet context can be loaded from them.
    The directory structure is like this
    Tiles Framework
    -Servlet Source
    -web.xml
    -tiles (folder)
    ---tile1(folder...contains the 1st website)
    ---tile2
    ---tile 3
    The reason being that in the older version of the shopping cart, the web.xml was used to load specfic contexts in the servlets.
    Is it possible that wach of the tiles has its own web.xml ?
    if so, does it require any configuration in the overall project.
    Thanks.

    If I understand the web.xml file correctly, there should only be one per project. But if it's just a matter of loading props for each of the tiles, can't you just have a different properties file for each tile?
    I can't imagine a situation where you'd be required to have multiple web.xml files within the same project. Can you explain why you can't just have several regular property files & read from them instead?

  • How can JSP access web.xml

    I have a JSP application that requires properties that are kept in a text file, which I am currently reading from. I would like to move these properties in the web.xml file and read them from there.
    I know how to read properties for a servlet from web.xml, however I do not know how to do this for a JSP. Can someone advise me?
    Thanks
    Matthew

    I'm not exactly sure what you are looking for, but if it's something you can do from a servlet, then you can do it from a JSP the same way. Remember, JSPs are compiled into servlets anyway. Just use the implicit objects (HttpServletRequest request, ServletContext application, etc)

  • Do I must put ALL my servlets inside the web.xml file?

    Hello everybody,
    I am trying to migrate from Webshere to TOMCAT a project with severals packets, one of those have 15 servlets and some classes.
    Is there any way to use the servlets without have to declare each one inside the web.xlm file ?
    Thanks in advance.

    All servlet definitions go into web.xml, though not the actual servlets themselves :) . Say if you wanted servlet A to have a different mapping you would define the mapping in web.xml to something other than the standard one.

  • Order of servlet mapping in web.xml

    Hello,
    is the order of multiple <servlet-mapping> in web.xml important? Or it doesn't matter in which order they are declared?
    For example, if i have two controllers, one is
    <servlet-name>Faces Servlet</servlet-name>
      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>
    and the second:
      <servlet>
        <servlet-name>FrontController</servlet-name>
        <servlet-class>servlets.FrontController</servlet-class>
      </servlet>
    and the mapping are:
       <servlet-mapping>
        <servlet-name>FrontController</servlet-name>
        <url-pattern>/jsf/*</url-pattern>
      </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
      </servlet-mapping>where /jsf/ contains jsp pages containing jsf components.
    is the order important?
    And may second question is:
    if i call the jsp page test.jsf in /jsf/test.jsp , which controller is responseble? Faces servlet or Frontcontroller?

    Here is what the 2.4 specification says on the matter (section SRV.11.1):
    >
    The path used for mapping to a servlet is the request URL from the request
    object minus the context path and the path parameters. The URL path mapping rules below are used in order. The first successful match is used with no further matches attempted:
    1. The container will try to find an exact match of the path of the request to the
    path of the servlet. A successful match selects the servlet.
    2. The container will recursively try to match the longest path-prefix. This is done by stepping down the path tree a directory at a time, using the �/� character as a path separator. The longest match determines the servlet selected.
    3. If the last segment in the URL path contains an extension (e.g. .jsp), the servlet container will try to match a servlet that handles requests for the extension. An extension is defined as the part of the last segment after the last �.� character.
    4. If neither of the previous three rules result in a servlet match, the container will attempt to serve content appropriate for the resource requested. If a "default" servlet is defined for the application, it will be used.
    The container must use case-sensitive string comparisons for matching.
    It also notes that in prior versions of the specification these were only a suggestion so if you are on servlet 2.3 or prior, you need to consult the documentation for your container.
    So, to answer your questions, no, order in the descriptor is not important.
    Also, based on the rules above, using your mappings, any URL starting with /jsf will be handled by FrontController including /jsf/test.jsp and /jsf/test.jsf.

  • How to create a simple web.xml for using servlets

    Hello i wanna configure the web.xml that i can use sevlets and beans, but how can i do that?
    This is de directorie i have installed my webapp
    C:\Tomcat 4.1\webapps\testapp
    C:\Tomcat 4.1\webapps\test\WEB-INF\classes (in this dir, I wanna put my beans and servlets, I got one servlet and the name is LogIn.class).
    And i wanna request my servlets with the url http://localhost:8080/testapp/servlet/LogIn
    How can i create a very basic web.xml with working beans, servlets and session? It is for testing-use only, so the security is not important for me at this moment.
    Tnx

    under your web-inf
    in your web.xml file you must map
    the servlets
    under the <web-app> tag type
    <servlet>
         <servlet-name>LogIn</servlet-name>
         <servlet-class>com.LogIn</servlet-class>
    </servlet>
    <servlet-mapping>
          <servlet-name>LogIn</servlet-name>
          <url-pattern>/LogIn</url-pattern>
    </servlet-mapping>ps: start using some IDE such as NetBeans or Ecclipse
    since they will take care of mapping all servlets and Beans
    and generate all the necessary files for your web-app

Maybe you are looking for

  • IPod Touch won't connect or charge AT ALL.

    I can't connect my iPod touch to ANY computer AT ALL. This includes Windows Xp, Vista and an iMac with Leopard. They are all running iTunes 7.6.2. I have tried all protocols I've come by so far none have worked. The iPod simply won't connect. The iPo

  • Error: c0000005 address: 39db7b7d

    Hello, I have the following problem: Every time, immediatly after I run Adobe Album SE - it gives me error: c0000005 on address: 39db7b7d, "Photoshop album has encountered a problem and needs to close.We are sorry for the inconvenience". I tryed with

  • Oracle Business Intelligence with big data

    Has anyone implemented OBIEE 10g utilizing a denormalized data model for a very large transactional data set? There is a potential to generate reports in the 100s of millions of rows, with the data warehouse storing fact tables that have ~1.5 billion

  • IOS 5 reminders due date issues

    Hi I'm having some trouble with the Reminders app in iOS 5. In iCal on my mac with OS X Lion I set some reminders with a due date. All these reminders sync well, but there are 2 issues in the app itself: 1. I can't sort the list of reminders by due d

  • How do I reinstall Premiere Pro CC on my new computer? I had a computer crash and need to reinstall the programme.

    How do I reinstall Premiere Pro CC on my new computer? I had a computer crash and need to reinstall the programme.