2014-11-25 18 views
1

저는 Spring MVC를 처음 사용하고 애플리케이션을 개발했습니다. 나는 Spring MVC Tutorial의 도움으로 프로젝트를 개발했다. 처음에는 작동했다. 그러나 Hibernate 4와 Spring 4로 프로젝트를 업그레이드하자마자 작업이 중단되었습니다. \ WEB-INF \ jsp를 호출 할 때마다 404 오류가 발생합니다./WEB-INF/jsp/폴더 내의 JSP에 액세스하지 않는 스프링

파일

인 LoginController

public class LoginController { 
     @RequestMapping(value="/login", method=RequestMethod.GET) 
     public ModelAndView showLoginPage(String path, ModelMap model){ 
      ModelAndView mv = new ModelAndView("login"); 
      model.addAttribute("welcome to Flight Services", "welcomeMessage"); 
      return mv; 
     } 
    } 

봄-servlet.xml에

<beans ......-mvc-4.0.xsd"> 
<mvc:annotation-driven /> 
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property> 
    <property name="prefix" value="/WEB-INF/jsp/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 
</beans> 

applicationContext.xml

 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" 
     xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:util="http://www.springframework.org/schema/util" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd 
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
      http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd 
      http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd 
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd 
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> 

    <context:annotation-config/> 
    <mvc:annotation-driven /> 

     <bean id="propertyConfigurer" 
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" 
      p:location="/WEB-INF/jdbc.properties"> 
     </bean> 
     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" 
     p:driverClassName="${jdbc.driverClassName}" 
     p:url="${jdbc.databaseurl}" 
     p:username="${jdbc.username}" 
     p:password="${jdbc.password}"> 

     </bean> 

     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
      <property name="dataSource" ref="dataSource" /> 
      <property name="configLocation"> 
      <value>classpath:hibernate.cfg.xml</value> 
      </property> 
      <property name="hibernateProperties"> 
       <props> 
        <prop key="hibernate.dialect">${jdbc.dialect}</prop> 
        <prop key="hibernate.show_sql">true</prop> 
       </props> 
      </property>  
     </bean> 
      <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven> 

     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
      <property name="sessionFactory" ref="sessionFactory" /> 
     </bean> 
    </beans> 

web.xml을하는 것은

<display-name>AirportService</display-name> 
    <servlet> 
    <servlet-name>spring</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>spring</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    <welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
    <welcome-file>index.htm</welcome-file> 
    <welcome-file>index.jsp</welcome-file> 
    <welcome-file>default.html</welcome-file> 
    <welcome-file>default.htm</welcome-file> 
    <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 
</web-app> 

는 index.jsp를

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
     pageEncoding="ISO-8859-1"%> 
     <%@include file="/WEB-INF/jsp/include.jsp" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
    <title>Insert title here</title> 
    </head> 
    <body> 
     <c:redirect url="/home" /> 
    </body> 
    </html> 

지금 때마다, 나는 나의 인덱스 페이지를 시작하고 있습니다. 이 오류가 발생합니다

org.apache.jasper.JasperException: /index.jsp (line: 3, column: 5) File "/WEB-INF/jsp/include.jsp" not found 
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42) 
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443) 
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:133) 
    org.apache.jasper.compiler.Parser.processIncludeDirective(Parser.java:322) 
    org.apache.jasper.compiler.Parser.parseIncludeDirective(Parser.java:357) 
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:467) 
    org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1779) 
    org.apache.jasper.compiler.Parser.parse(Parser.java:135) 
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242) 
    org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:119) 
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:193) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:373) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353) 
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340) 
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 

답변

0

존재하지 않는 "/WEB-INF/jsp/include.jsp"파일을로드하려고합니다. index.jsp 파일에 다음 줄이 있습니다.

<%@include file="/WEB-INF/jsp/include.jsp" %> 

오류 로그에 따르면이 파일은 존재하지 않습니다. 올바른 디렉토리에 있습니까?

+0

에 관심이있는 모든 확장자로 교체 할 수 있습니다. 여기서, 폴더 구조 └───WebContent ├───META-INF는 └───WEB-INF ├───jsp 이다 └───lib – Ashish

0

어쨌든 스프링과 Hibernate 버전을 3.x로 다운 그레이드하고 작동 중입니다. 여기에 버전 4의 트릭이 없다고 생각됩니다.

0

맞으면 index.jsp가 WEB-INF 외부에 있고 액세스하려는 리소스가 WEB-INF 안에 있습니다. WEB-INF 외부의 자원 (예 : 이미지, HTML 및 기타 정적 HTML 자료)은 WEB-INF에있는 컨텐츠에 액세스 할 수 없음을 기억하십시오. 그래서 당신은 <%@include file="/WEB-INF/jsp/include.jsp" %>

당신은이 작업을 수행 할 수 있습니다 수행 할 수 없습니다 include.jsp 및 index.jsp를 모두 내부 또는 외부 WEB-INF 같은 위치에있는

<%@include file="include.jsp" %>합니다.

<url-pattern>/</url-pattern> .HTM <url-pattern>*.htm</url-pattern>에 대체 당신의 web.xml에

(선택 사항)을 Yes (예)이 파일이 해당 디렉토리에 존재