2016-04-12 1 views
0

Заголовок говорит, что все это действительно так. У меня есть небольшой веб-проект Spring, который при запуске должен открыть redirect.jsp в моем браузере. Это должно отправить мне через контроллер по умолчанию до home.jsp. Проблема в том, что нет. Вместо этого он автоматически открывает некоторую страницу индекса по умолчанию в моем браузере. Отображаемая страница индекса не существует в моем проекте, имеет заголовок «Стартовая страница» и показывает только заголовок с «Hello World». Как ни странно, URL-адрес моего браузера - это только localhost:port/projectrootfolder, а не localhost:port/projectrootfolder/home.htm или что-то подобное.Почему веб-проект Spring не загружает правильную страницу при запуске?

Моя структура проекта

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

Мой диспетчеру-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> 

Мой 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> 

Мой 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 является home.htm – LearningPhase

+0

Это должно быть/дома – LearningPhase

+0

Должно быть/дома, как ваш контроллер будет иметь отображение перенаправлять его to home.jsp – LearningPhase

ответ

0

UPDATE:

Изменить это:

<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

Нет, я все еще получаю страницу Hello World. – Exevan

+0

Что такое home.jsp? это страница, которую вы хотите показать? вы хотите показать home.jsp или home.html? – FreezY

+0

Учитывая, что я не перечислил файл home.html в моей структуре проекта и что такой файл даже не существует в моем проекте, я бы сказал, что его довольно очевидно, что я пытаюсь загрузить home.jsp. – Exevan

Смежные вопросы