2017-02-14 1 views
0

뷰의 이름을 마지막으로 확인한 문자열을 반환하는 public function index()가있는 단일 컨트롤러 클래스 (MainController.class)와의 전쟁 프로젝트가 있습니다. "index.jsp"라는 단일 JSP로 전달되었습니다. 뷰는/main/webapp/WEB-INF/views/jsp /에 있습니다. MainController.java :Spring MVC 요청한 리소스를 사용할 수 없습니다.

@Controller 
public class MainController 
{ 
    @Autowired 
    private ApplicationContextProvider mObjApplicationContextProvider; 

    @Autowired 
    private ScheduleService mObjScheduleService; 

    protected ApplicationContext getApplicationContext() 
    { 
     return(getApplicationContextProvider().getApplicationContext()); 
    } 

    protected ApplicationContextProvider getApplicationContextProvider() 
    { 
     return(mObjApplicationContextProvider); 
    } 

    protected Object getBean(final Class<?> clsBean) 
    { 
     return(getApplicationContext().getBean(clsBean)); 
    } 

    protected Object getBean(final String sBeanName) 
    { 
     return(getApplicationContext().getBean(sBeanName)); 
    } 

    protected ScheduleService getScheduleService() 
    { 
     return(mObjScheduleService); 
    } 

    @RequestMapping(value="/") 
    public String index() 
    { 
     return("index"); 
    } 
} 

의 index.jsp :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
     <title>Insert title here</title> 
    </head> 
    <body> 
     Hello World! 
    </body> 
</html> 

내 구성 XML 파일 : 나는 내 브라우저에서 오류가 몇 가지 이유를 들어

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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"> 

    <context:component-scan base-package="net.draconia.church" /> 

    <bean class="net.draconia.ApplicationContextProvider" /> 

    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource"> 
     <property name="driverClassName" value="com.mysql.cj.jdbc.Driver" /> 
     <property name="url" value="jdbc:mysql:sql9.freemysqlhosting.net/sql9158326" /> 
     <property name="username" value="sql9158326" /> 
     <property name="password" value="MqX7sbacgB" /> 
    </bean> 

    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix" value="/WEB-INF/views/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

    <mvc:resources mapping="/resources/**" location="/resources/" /> 

    <mvc:annotation-driven /> 

</beans> 

나는 "http://localhost:8080/Ushering/에 이동 ": 404 -"요청한 리소스를 사용할 수 없습니다. "

로그에서 아무 것도 찾을 수 없지만 필요한 경우 게시하여 어떤 파일이나 리소스를 사용할 수 없는지 알려줍니다. 하나의 로그 파일에서 컨트롤러에 대한 요청 매핑을 언급하기 때문에 컨트롤러를 찾을 수있는 것 같습니다. 뭐가 될수 있었는지?

편집 : WAR 파일은 pom 파일에 정의 된대로 Ushering이며 프로젝트의 이름으로 web.xml에도 정의되어 있으므로 컨텍스트가 Ushering이고 Spring 응용 프로그램 측면에있는 것으로 생각됩니다. 것들은/Ushering 이후에/Hello에 requestmapping을 설정하면 URL은 localhost : 8080/Ushering/Hello 여야합니다.

편집 : 내 web.xml 파일

<?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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> 
    <display-name>CrunchifySpringMVCTutorial</display-name> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
    </welcome-file-list> 

    <servlet> 
     <servlet-name>Ushering</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/Ushering-config.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Ushering</servlet-name> 
     <url-pattern>/s</url-pattern> 
    </servlet-mapping> 
</web-app> 
+0

web.xml 파일을 게시 할 수 있습니까? – dennislloydjr

+0

수정으로 추가했습니다. –

+0

알았습니다! web.xml -/s를 url 패턴의 하단에 게시했을 때 오타가 나타났습니다. /이어야합니다 /. 나는 's'을 삭제하고, 깨끗한 컴파일 전쟁 : war-ed 그것을 예상하고있다 :-D 날 올바른 방향으로 파고 주셔서 감사합니다! –

답변

0

당신이 당신의 MainController 클래스를 보면 "인덱스"를 반환 방법을 처리하는 하나의 요청 만이있다. "/"에 맵핑되어 localhost : 8080을 입력하면 색인 파일이 반환됩니다. 따라서 대신 localhost : 8080/Ushering을 입력하십시오. 로컬 호스트 : 8080. 그것은 효과가있을 것이다. 그러나 localhost : 8080/Ushering을 입력하려면 컨트롤러 파일의 요청 매핑을 다음과 같이 변경하십시오.

@RequestMapping (값 = "/ 도래")는

public String index() 
{ 
    return("index"); 
} 

그것은 당신에게 인덱스 파일을 반환합니다.

+0

어떻게 될지 모르겠다. 전쟁은 Ushering.war이고 war 파일을 webapp로 복사 할 때 Tomcat의 WebApps 폴더 아래에 컨텍스트를 만든다. http : // localhost : 8080을 입력하면 "공식적으로 Tomcat을 설치했습니다! 축하합니다!"라는 메시지가 나타납니다. 페이지. –

관련 문제