Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Java (http://www.programmingforums.org/forum17.html)
-   -   Spring Framework Controller (http://www.programmingforums.org/showthread.php?t=15132)

big_k105 Feb 6th, 2008 11:18 PM

Spring Framework Controller
 
I have been playing around with java web programming a lot lately, and am using the Spring Framework MVC to do this. My problem is that when I go to the url http://localhost:8080/Forum/index.html the spring framework calls the controller it is suppose to call, but when I go to http://localhost:8080/Forum/ it won't call the controller, and I can't seem to figure out how I can get it to do that.

Below is my web.xml file:
:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  3.   <display-name>Forum</display-name>
  4.  
  5.   <servlet>
  6.           <servlet-name>springapp</servlet-name>
  7.           <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  8.           <load-on-startup>1</load-on-startup>
  9.   </servlet>
  10.  
  11.   <servlet-mapping>
  12.           <servlet-name>springapp</servlet-name>
  13.           <url-pattern>*.html</url-pattern>
  14.   </servlet-mapping>
  15.  
  16.   <welcome-file-list>
  17.     <welcome-file>index.jsp</welcome-file>
  18.   </welcome-file-list>
  19.  
  20. </web-app>


Below is my springapp-servlet.xml
:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
  3.  
  4. <!--
  5.   - Application context definition for "springapp" DispatcherServlet.
  6.   -->
  7.  
  8. <beans>
  9.         <!-- TILES CONFIG -->
  10.         <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
  11.             <property name="definitions">
  12.                     <list>
  13.                             <value>/WEB-INF/tiles-defs.xml</value>
  14.                     </list>
  15.             </property>
  16.           </bean>
  17.  
  18.         <bean id="defaultController" class="com.kydovik.forum.controller.BaseController" />
  19.         <bean id="forumController" class="com.kydovik.forum.controller.ForumController" />
  20.         <bean id="threadController" class="com.kydovik.forum.controller.ThreadController" />
  21.  
  22.         <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
  23.                 <property name="mappings">
  24.                         <value>
  25.                                 /index.html=defaultController
  26.                                 /**/ShowForum.html=forumController
  27.                                 /**/ShowThread.html=threadController
  28.                         </value>
  29.                 </property>
  30.         </bean>
  31.  
  32.         <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  33.           <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
  34.                           <property name="prefix">
  35.                         <value>/</value>
  36.                 </property>
  37.                 <property name="suffix">
  38.                         <value>.jsp</value>
  39.                 </property>
  40.         </bean>
  41. </beans>


ReggaetonKing Feb 7th, 2008 2:11 PM

Re: Spring Framework Controller
 
EDIT: Nevermind. Sorry.

Maybe you need to play with the mapping options more. All I can think of.

pushkarajthorat Feb 11th, 2008 7:05 AM

Re: Spring Framework Controller
 
when you call any URL; procedure to locate this resource within the webserver is:

for a URL:
<http|https>://<hostname|IP>[:portno]/<ApplicationName>/[Resource]
1: Go to the <ApplicationName>'s web.xml
2: Find the matching servlet-mapping tag with <url-pattern> regex. for URL:/[Resource] Go to the servelet-mapping tag.. and execute the servelet-class tag servelet
3: If there is no Servelet-mapping match then resource not found error is displayed.
4: if URL:/[Resource] is blank it will take each <welcome-file> from <welcome-file-list> is taken and used as URL:/[Resource] and execute the whole thing from 2: skipping the 3rd point.

In your second case http://localhost:8080/Forum/ resource is blank and specified welcome-file "index.jsp" is not matching with any servelet-mapping tag's <url-pattern> so... Insted of <url-pattern>*.html</url-pattern> put <url-pattern>*.*</url-pattern> in servelet-mapping tag.. so scope of index.jsp will within the front controller.


All times are GMT -5. The time now is 4:07 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC