8 Replies Latest reply on Aug 20, 2003 3:55 AM by 74greg

    JSP with Servlet Problem

    ggopal

      I have an application that has JSP's containing forms which call servlets in the backend for processing. The form's action is formatted as '/servlet/xxx.xxx.xxx.prog1' where xxx is the package. Currently, the entire application runs under iplanet and it runs fine.

      I am trying to migrate to jboss 3.2.1 with tomcat and I am very confused as to how I can make this work. I am able to load my jsp, but, jboss is not able to load the servlet from the jsp. I have tried to change the context. All of the classess are in WEB-INF/classes, web.xml is populated with all the servlets and their URL mapping. I have created a war which is unpacked with just a dir under JBOSS_DIST/server/default/deploy/myapp.war.

      I am not familiar with jboss, so I would appreciate very much if someone can help. It's probably simple, but right now the solution eludes me.

      1) What should the form's action read if the form is in a jsp or html and the servlet is in a java package of the form xxx.xxx.xxx.prog1?
      2) How should I configure jboss to look for servlets? I thought that having the classes under WEB-INF/classes should do the trick/

      Thanks

        • 1. Re: JSP with Servlet Problem
          jonlee

          JBoss itself plays little part in the physical operation of the web application. This is controlled by Tomcat, running as a service under the JBoss microkernel. So for most questions, you should defer to the Tomcat documentation.

          JBoss has one override on Tomcat and that is on the infrastructure hooks to which Tomcat has access. This configuration is contained in server/default/deploy/jbossweb-tomcat.sar/META-INF/jboss-service.xml. This borrows much from the Tomcat server.xml, allowing you to configure mainly the connector/listener configurations.

          The Tomcat servlet/JSP configurations are contained in server/default/deploy/jbossweb-tomcat.sar/web.xml. This is a standard Tomcat configuration. Tomcat as rolled into the JBoss distribution has anonymous servlet support switched off as this is an identified security issue. So unless servlets are specifically mapped, /servlet/MyServlet will not work. I don't know if this affects the iPlanet configuration.

          So in the web.xml, you need the following definition pair:


          <servlet-name>Verify</servlet-name>
          <servlet-class>com.amity.cardflex.servlet.Verify</servlet-class>


          <servlet-mapping>
          <servlet-name>Verify</servlet-name>
          <url-pattern>/verify</url-pattern>
          </servlet-mapping>

          In order to directly call the servlet code in com.amity.cardflex.servlet.Verify, the URI would be /MyContext/verify matching the /verify mapping. And com.amity.cardflex.servlet.Verify exists under WEB-INF/classes of your WAR.

          Your JSP would have a form action such as:

          This is assumes that your JSP is at the root level for your context and we have already defined the servlet to map to the root level of the context.

          Note that the actual package is not conveyed in the action and neither is the real class name of the servlet servicing the call. You should be able to extend from this simple example.

          Hope that helps.

          • 2. Re: JSP with Servlet Problem
            ggopal

            JonLee:

            So, what you are saying is that all my servlets along with their respective mapping needs to be defined under JBOSS_DIST/server/default/deploy/jbossweb-tomcat.sar/web.xml.

            I have all my servlets and their mapping defined under JBOSS_DIST/server/default/deploy/myapp.war/WEB-INF/web.xml.

            So, I am confused now as to where the servlet definitons and their mappings should be kept?

            In addition, JBOSS_DIST/server/default/deploy/myapp.war/WEB-INF/jboss-web.xml, jboss doesn't seem to read this file. I am trying to change the default context to the root as per the various examples in the forum, but, this isn't working either. Would you be able to figure out why, please?

            JonLee, I am about tearing my hair out at the moment. I have been trying to resolve this for a while and the more I read the more I get confused. I think the solution is simple.

            Thanks for your response.

            -- Gopal

            • 3. Re: JSP with Servlet Problem
              jonlee

              No. You need to change you local web.xml (in your WAR) for your servlet mappings. That was my fault for not making that clear.

              The web.xml in server/default/deploy/jbossweb-tomcat.sar defines global operations for Tomcat - such as how the JSP compiler Jasper runs, what to normally do with directories that do not have a welcome file and so on. And you will find in that file some definitions on how Tomcat will invoke servlets.

              You can override certain aspects of the global definitions in your local web.xml, located in your own WAR. So when I spoke about the mapping, I meant you need to define your servlet name and also the servlet-mapping tags locally (in your own web.xml as they apply only to your local context). So the specific information I have provided applies to your local context.

              I also gave you some general information so you know what exists for the Tomcat configuration. You will need to read more about Tomcat from the Tomcat website - http://jakarta.apache.org/tomcat. You also need to understand that JBoss is not Tomcat and vice-versa so much of the questions you may have in the future about Tomcat can be found at the Tomcat site as it might not be able to be answered adequately here - particularly if the question asks about specifics like the operation of the JSP compiler and so on.

              Hope that clarifies things.

              • 4. Re: JSP with Servlet Problem

                For /servlet/*

                If you look in jbossweb-tomcat.sar/web.xml
                there is an invoker servlet
                which is disabled, you have to configure the servlet
                mapping.

                That is a very old-fashioned way of configuring
                servlets.

                I don't know why your jboss-web.xml isn't working,
                try posting it.

                Regards,
                Adrian

                • 5. Re: JSP with Servlet Problem
                  ggopal

                  Thanks a bunch jonlee and warjort.

                  Current situation is that everything works.

                  warjort, yes I did see the invoker and decided to leave it alone.

                  As for my jboss-web.xml, it seems to be working. I have only one entry for context-root as "/". I am curious about how I can verify it, though.

                  Does something gets written to the server.log? I don't know ..

                  My heartfelt gratitude to you guys for jumping in and providing a solution.

                  Now the only question I have is for my welcome-file-list. I have set it to my login page.jsp file, but, it does not seem to get loaded. Of course, all my jsp's are within the /jsp subdir of JBOSS_DIST/server/default/depoly/myapp.war.

                  How can I set it so that I can load my login page as a welcome page during startup?

                  I have the welcome-file-list tag in my local web.xml, but, that doesn't seem to work. I have also put the same entries in JBOSS_DIST/server/default/deploy/jbossweb-tomcat.sar/web.xml. That doesn't seem to work either ...

                  What I mean is that when I sayt http://localhost:, it should have displayed my login page and it doesn't.

                  Thanks again,
                  -- Gopal

                  • 6. Re: JSP with Servlet Problem
                    haraldgliebe

                    > As for my jboss-web.xml, it seems to be working. I
                    > have only one entry for context-root as "/". I am
                    > curious about how I can verify it, though.

                    What happens if you point your browser to http://localhost:8080 ? Do you get a directory listing of mywap.war ?

                    >
                    > Does something gets written to the server.log? I
                    > don't know ..
                    >
                    When your web-app is deployed you should get an entry in the log file similar to:

                    00:48:59,441 INFO [jbossweb] successfully deployed file:/C:/jboss-3.2.1/server/default/deploy/test.war/ to

                    > Now the only question I have is for my
                    > welcome-file-list. I have set it to my login page.jsp
                    > file, but, it does not seem to get loaded. Of course,
                    > all my jsp's are within the /jsp subdir of
                    > JBOSS_DIST/server/default/depoly/myapp.war.
                    >
                    The WebContainer uses the entries in the welcome-file-list, when a directory is requested. It then tries to find the file in this list in the requested directory and returns the first one found.
                    If you put jsp/login.jsp in this list, it would only work for the root of you web-app (http://localhost:).

                    > How can I set it so that I can load my login page as
                    > a welcome page during startup?
                    >
                    > I have the welcome-file-list tag in my local web.xml,
                    > but, that doesn't seem to work. I have also put the
                    > same entries in
                    > JBOSS_DIST/server/default/deploy/jbossweb-tomcat.sar/w
                    > b.xml. That doesn't seem to work either ...
                    >
                    In general you shouldn't need to edit the web.xml in jbossweb-tomcat.sar since it only provides defaults, that can be overriden in the web.xml of your web-app.

                    > What I mean is that when I sayt
                    > http://localhost:, it should have displayed my
                    > login page and it doesn't.
                    >
                    What do you get then? A directory listing or an error ?

                    Regards,
                    Harald

                    • 7. Re: JSP with Servlet Problem

                      It works for me, what does your config look like.

                      Login pages are normally configured using form login-config

                      Regards,
                      Adrian

                      • 8. Re: JSP with Servlet Problem
                        74greg

                        Thanks guys for those advices!!!

                        I had also a pb to run my servlet, and thanks to this topic, i find a solution: uncomment the invoker part
                        in jbossweb-tomcat.sar/web.xml file.


                        I'm now able to run JSP & servlets with JBoss.

                        Thnks again.