2014-05-21 2 views
0

저는 java/spring/hibernate를 사용하여 mvc 웹 응용 프로그램을 개발하려고합니다.Java/Spring MVC 시작 페이지 프로젝트?

사실 모든 구성을 완료 한 후에는 문제가 발생했습니다.

이 내 web.xml을

<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_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>BookStore</display-name> 

    <context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath:applicationcontext.xml</param-value> 
    </context-param> 

    <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <servlet> 
    <servlet-name>mvc-dispatcher</servlet-name> 
    <servlet-class> 
        org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>mvc-dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 

</web-app> 

입니다 그리고 이것은

<?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:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 

    <bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix"> 
      <value>pages/</value> 
     </property> 
     <property name="suffix"> 
      <value>.jsp</value> 
     </property> 
    </bean> 

    <!-- Used for scan Controller Spring annotations --> 
    <context:component-scan 
     base-package="progettoPW.BookStore.backend.servlet.controller" /> 

    <bean name="/index" class="progettoPW.BookStore.backend.servlet.HomeServlet" /> 

</beans> 

(HomeServlet의 index.jsp 페이지에 응용 프로그램을 리디렉션) 내 프로젝트 작품 내 MVC-디스패처-servlet.xml 파일입니다 한 가지만을위한 좋은 점 : URL을 사용할 때

http://localhost:8080/BookStore/ 

나는 404 오류가 발생했습니다. 또는. 난 내가

<welcome-file-list> 
    <welcome-file>/index</welcome-file> 
</welcome-file-list> 

난 그냥 내가 시작하는 URL을 사용하면 내 인덱스 페이지에 가고 싶어이 태그를은 web.xml에 추가 tryed했습니다 http://localhost:8080/BookStore/index

사용했습니다 http://localhost:8080/BookStore/

도움? 감사

답변

1

당신은 아마 당신의 MVC-디스패처-servlet.xml 파일에 다음 줄을 추가 할 수 있습니다

<mvc:view-controller path="/" view-name="redirect:/index" /> 

PS를 : 당신이 당신의 beans 루트 태그에 mvc 스키마를 추가해야합니다 :

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    ... 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation=" 
     ... 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd"> 
+0

감사합니다. 정말 잘 작동합니다. – Alist3r

0

<welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 

를 사용하여 시도 적이 있습니까?