2013-06-06 3 views
0

바람둥이와 이클립스로 스프링 MVC를 구성하는 방법에 대한 많은 설명이있다. 제가 누락 된 부분이 궁금합니다. 이미 다른 솔루션을 확인했지만 아무도 나를 도와주지 않습니다. 1)의 web.xml :스프링 MVC + 이클립스 + 톰캣

<?xml version="1.0" encoding="UTF-8"?> 
<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" version="2.5"> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/spring/root-context.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> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 
<welcome-file-list> 
    <welcome-file>index.jsp</welcome-file> 
</welcome-file-list> 

2) 디스패처-servlet.xml에

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> 

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

<!-- Enables the Spring MVC @Controller programming model --> 
<annotation-driven /> 

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
<resources mapping="/resources/**" location="/resources/" /> 

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --> 
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <beans:property name="prefix" value="/WEB-INF/views/" /> 
    <beans:property name="suffix" value=".jsp" /> 
</beans:bean> 

<context:component-scan base-package="com.controle.pronto" /> 
</beans:beans> 

3)의 index.jsp 여기

은 내가 사용하는 파일입니다

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ page session="false" %> 
<html> 
    <head> 
     <title>Home</title> 
    </head> 
    <body> 
     <h1>Hello world!</h1> 
    </body> 
</html> 

4) HomeController.java package com.controle.pronto; 내가 액세스 할 때

import java.text.DateFormat; 
import java.util.Date; 
import java.util.Locale; 

import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

/** 
* Handles requests for the application home page. 
*/ 
@Controller 
public class HomeController { 

private static final Logger logger = LoggerFactory.getLogger(HomeController.class); 

/** 
* Simply selects the home view to render by returning its name. 
*/ 
@RequestMapping(value = "/", method = RequestMethod.GET) 
public String home(Locale locale, Model model) { 
    logger.info("Welcome home! The client locale is {}.", locale); 

    Date date = new Date(); 
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); 

    String formattedDate = dateFormat.format(date); 

    model.addAttribute("serverTime", formattedDate); 

    return "home"; 
} 
} 

5) 그리고 여기 내 worskspace 구조

src 
    main 
     webapp 
      WEB-INF 
       views 
        home.jsp 
       dispatcher-servlet.xml 
       web.xml 
      index.jsp 

입니다 : - 로컬 호스트 : 8080/controleponto - 로컬 호스트 : 8080/controleponto/인덱스 - 로컬 호스트 : 8080/controleponto/index.jsp 404 페이지로 - 요청한 리소스를 사용할 수 없습니다.

내가 잘못하고있는 것에 대해 의견을 보내 주시면 감사하겠습니다.

감사합니다, 루이스 아마 랄

+1

컨트롤러는 어떻습니까? – Patison

+0

응용 프로그램의 컨텍스트 루트가 'controleponto'인지 확인하십시오. tomcat 관리자를 사용하여이를 확인하거나 Eclipse 프로젝트 속성을 확인할 수 있습니다. 또한 컨트롤러 구성 방법은 무엇입니까? –

+0

방금 ​​HomeController.java로 업데이트했습니다. –

답변

1

은 server.xml 파일로 이동합니다. 컨텍스트 루트가 있습니다. 이

<Context docBase="yourApp" path="/yourApp" reloadable="true" source="org.eclipse.jst.jee.server:yourApp"/></Host> 

한번에 로딩 localhost:8080/yourApp 같은 당신이 처음에 포트 8080

+0

예 ... server.xml을 볼 수 있습니다 :

+0

하지만 여전히 작동하지 않습니다. ( –

+0

어쩌면 문제는 바람둥이를 시작할 때입니다.이 로그를 봅니다 : 'source'속성을 'org.eclipse.jst.jee.server : controleponto'로 설정하면 일치하는 속성을 찾지 못했습니다. –

0

에 바람둥이를 실행하는 가정, 서버는 인덱스 파일을 검색합니다. 따라서 webapp 디렉토리 외부의 index.jsp 파일을 지나쳐야합니다.

또한 dispatcher-servlet.xml에 추가해보십시오.

0

먼저 로컬 : 8080으로 실행하십시오. 실행중인 경우 다음 Tomcat이 잘 작동한다는 것을 의미합니다.

웹 응용 프로그램 바로 아래에 간단한 .html 파일을 넣은 다음 마우스 오른쪽 단추로 클릭하면 서버로 실행되어 eclipse에서 실행 된 것을 볼 수 있습니다. 그런 다음 응용 프로그램에서 웹 응용 프로그램에 사용하는 실제 이름을 알 수 있습니다.

모든 것이 원활하게 실행되는 것보다 시간이 많이 걸렸습니다.

관련 문제