2016-04-12 35 views
0

Başlık, tüm bunları gerçekten söyler. Açılışta tarayıcımda redirect.jsp'u açacak küçük bir Spring web projem var. Bu bana varsayılan denetleyiciden home.jsp'a göndermelidir. Sorun şu ki değil. Bunun yerine tarayıcımda otomatik olarak bazı varsayılan dizin sayfasını açar. Gösterdiğim dizin sayfası projemde mevcut değil, "Başlangıç ​​Sayfası" başlığına sahip ve sadece "Merhaba Dünya" ile bir başlık gösteriyor. Garip bir şekilde, tarayıcımdaki URL sadece localhost:port/projectrootfolder ve localhost:port/projectrootfolder/home.htm veya benzeri bir şey değil.İlkbahar web projem başlangıçta neden doğru sayfayı yüklemiyor?

Projem yapısı

root 
|... 
|Web pages 
| |WEB-INF 
| | |jsp 
| | | |home.jsp  
| |dispatcher-servlet.xml 
| |web.xml 
|redirect.jsp 

Benim memuru-servlet.xml

<?xml version='1.0' encoding='UTF-8' ?> 
<!-- was: <?xml version="1.0" encoding="UTF-8"?> --> 
<beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:p="http://www.springframework.org/schema/p" 
      xmlns:aop="http://www.springframework.org/schema/aop" 
      xmlns:mvc="http://www.springframework.org/schema/mvc" 
      xmlns:context="http://www.springframework.org/schema/context" 
      xmlns:tx="http://www.springframework.org/schema/tx" 
      xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-4.0.xsd 
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">  
    <!-- Specify that this dispatcher works with by spring annotations--> 
    <mvc:annotation-driven conversion-service="conversionService"/> 
    <context:component-scan base-package="com.exevan.ipweb.controller" />   
    <!-- Spring bean that maps url's to controllers --> 
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
     <property name="mappings"> 
      <props> 
       <prop key="home.htm">homeController</prop> 
      </props> 
     </property> 
    </bean>  
    <!-- Spring bean that converts logical view name to view location --> 
    <bean id="viewResolver"   class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
       p:prefix="/WEB-INF/jsp/" 
       p:suffix=".jsp" /> 

    <!-- Index controller --> 
    <bean name="homeController"    class="org.springframework.web.servlet.mvc.ParameterizableViewController" 
       p:viewName="home" /> 

    <bean id="conversionService"    class="org.springframework.context.support.ConversionServiceFactoryBean"> 
     <property name="converters"> 
      <list> 
       <bean id="dateToStringConverter" class="com.exevan.ipweb.converter.DateToStringConverter"/> 
       <bean id="stringToDateConverter" class="com.exevan.ipweb.converter.StringToDateConverter"/> 
       <bean id="idToPublisherConverter" class="com.exevan.ipweb.converter.IdToPublisherConverter"/> 
      </list> 
     </property> 
    </bean>   
</beans> 

Benim web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/applicationContext.xml</param-value> 
    </context-param> 
    <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>dispatcher</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>2</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>dispatcher</servlet-name> 
     <url-pattern>*.htm</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout> 
      30 
     </session-timeout> 
    </session-config> 
    <welcome-file-list> 
     <welcome-file>redirect.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

Benim redirect.jsp

<%-- 
Views should be stored under the WEB-INF folder so that 
they are not accessible except through controller process. 

This JSP is here to provide a redirect to the dispatcher 
servlet but should be the only JSP outside of WEB-INF. 
--%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<% response.sendRedirect("/home.htm"); %> 
+0

myredorect.jsp Üzerinde yönlendirme Denetleyiciniz onu yönlendirmek eşleme olurdu gibi/home – LearningPhase

+0

olduğunu to home.jsp – LearningPhase

+0

olmalı/home olmalıdır home.htm – LearningPhase

cevap

0

GÜNCELLEME:

Değişim bu:

<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/</url-pattern>   <------- Change this 
    <url-pattern>/home.htm</url-pattern> <------- Add this 
</servlet-mapping> 
<session-config> 
    <session-timeout> 
     30 
    </session-timeout> 
</session-config> 
<welcome-file-list>      
    <welcome-file>/home.htm</welcome-file> <------- Change this 
</welcome-file-list> 
+0

Hayır, hala Hello World sayfasını aldım. – Exevan

+0

home.jsp dosyası nedir? göstermek istediğiniz sayfa bu mu? home.jsp veya home.html göstermek mi istiyorsunuz? – FreezY

+0

Proje yapmamda bir home.html dosyası listelemediğimi ve projemde böyle bir dosyanın bulunmadığını düşünürsek, home.jsp dosyasını yüklemeye çalıştığımı açıkça söyleyebilirim. – Exevan

İlgili konular