Announcement Announcement Module
Collapse
No announcement yet.
abstractcontroller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • abstractcontroller

    hi,

    I am trying to exp with the abstractController

    these are my files

    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>
        <display-name>testAbstractController</display-name>
    
        <description>
            test the abstract controller to see whether it takes in accepts posts and gets
        </description>
    
    
        <servlet>
            <servlet-name>dispatch</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>dispatch</servlet-name>
            <url-pattern>/testAbstractController</url-pattern>
        </servlet-mapping>
    
        <context-param>
            <param-name>log4jConfigLocation</param-name>
            <param-value>WEB-INF/log4j.xml</param-value>
        </context-param>
    
        <!--<context-param>-->
            <!--<param-name>webAppRootKey</param-name>-->
            <!--<param-value>testAbstractController.root</param-value>-->
        <!--</context-param>-->
    
        <listener>
            <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
        </listener>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
    
        <welcome-file-list>
            <welcome-file>index.html</welcome-file>
        </welcome-file-list>
        
    </web-app>
    applicationContext.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC  "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
        <!--DATA SOURCE BEANS -->        
    </beans>
    dispatch-servlet.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
               http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
        <bean id="testAbstractController" class="au.com.test.SampleController"/>            
    
        <!-- URL MAPPING -->
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="/testAbstractController">testAbstractController</prop>
                </props>
            </property>
        </bean>
    </beans>
    and finally my SampleController.java
    Code:
    package au.com.test;
    
    import org.springframework.web.servlet.mvc.AbstractController;
    import org.springframework.web.servlet.ModelAndView;
    import org.apache.log4j.Logger;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Created by IntelliJ IDEA.
     * User: Chris
     * Date: Jun 30, 2007
     * Time: 6:51:29 PM
     * To change this template use File | Settings | File Templates.
     */
    public class SampleController extends AbstractController {
        private static Logger log = Logger.getLogger(SampleController.class);
        
        public ModelAndView handleRequestInternal(
            HttpServletRequest request,
            HttpServletResponse response)
        throws Exception {
            log.debug("hello i am here");
            ModelAndView mav = new ModelAndView();
            
            return mav;
        }
    }
    All I want to do is to trigger the log but I do not know how to do it from the browser any help would be appreciated.

    I have tried http://localhost:8080/testAbstractController but all I get is a 404 error.

  • #2
    I have tried http://localhost:8080/testAbstractController but all I get is a 404 error
    What you want to do is have the "dispatch" in your web.xml handle requests "/test/*.html" and then in your dispatch-servlet.xml have entries like "foo.html" in your SimpleUrlHandlerMapping. Then go to the URL "/test/foo.html"

    http://static.springframework.org/sp...handlermapping

    explains it all.

    Comment


    • #3
      test abstractcontroller

      Hi,

      thanks for the quick reply however i do not intend to use *.html files or anything like that i intend to use the abstractcontroller like a servlet and instead of writing code for doGet and doPost.Am i going abot this the right way?

      Comment


      • #4
        I wonder if "/testAbstractController" gets to the handler mapping at all. I'm not quite sure (would need to look it up) if the stuff used for servlet mapping is stripped and not used for handler mapping. So you might try some servlet mapping on "/testAbstractController/*" in servlet mapping and some "/*" in handler mapping.

        Jörg

        Comment


        • #5
          abstractController

          thanks for that

          Comment


          • #6
            this might sound like a stupid question and I know its more tomcat than here,

            at the moment it works when I do

            http://localhost:8080/testAbstractController/testAbstractController/{can put whatever I want here}

            my actual sampleController class is in a jar file called testAbstractController.jar

            and my war file name is testAbstractController

            so what I want to know is the 2nd testAbstractController does that mean I have to query it inside the jar file. I understand why the first testAbstractController is needed but do not understand why a 2nd one is needed.

            Thanks

            Comment


            • #7
              http://localhost:8080/testAbstractController/testAbstractController/{can put whatever I want here}
              That's because your web.xml sends all requests to /testAbstractController/* to whatever you've defined as your DispatcherServlet. You can try putting in "/" in your SimpleURLHandler.

              Comment


              • #8
                Originally posted by lasher169 View Post
                so what I want to know is the 2nd testAbstractController does that mean I have to query it inside the jar file. I understand why the first testAbstractController is needed but do not understand why a 2nd one is needed.
                The first is from the web application context. It's mounted on /testAbstractController since you probably dropped in a war of the same name and Tomcat falls back to a default behaviour (war name => context).

                The second is from the servlet-mapping inside your web.xml. That's the path INSIDE your web application. But it has nothing to do with a package name inside the jar, it's only the servlet mapping since you can have multiple servlets in one web application.

                Jörg

                Comment


                • #9
                  thanks for your reply

                  so if i want to just do

                  Code:
                  http://localhost:8080/testAbstractController/testController
                  for testing

                  I can do in my web.xml

                  Code:
                  <url-patter>*/*</url-patter>
                  then in my dispatch mapping have

                  Code:
                  <prop key="/testController">testAbstractController</prop>
                  is that correct

                  Comment


                  • #10
                    I have worked out why thanks for everyone for their help for anyone who is vaguely interested this is explains how the url-pattern works

                    http://edocs.bea.com/wls/docs61/weba...l.html#1039540

                    I know it applies to weblogic but i dont think the part is different to tomcat

                    Comment


                    • #11
                      Originally posted by lasher169 View Post
                      I know it applies to weblogic but i dont think the part is different to tomcat
                      Actually it's from the servlet spec, nothing specific to the one or the other servlet container (besides implementation errors).

                      Jörg

                      Comment

                      Working...
                      X