2012-01-23 2 views
6

JAX-RS '(저지) MVC 패턴을 사용하려고합니다. 시도라는 오류에 http://localhost:8080/myproject/foos/test 결과에 도달 : 같은 오류JAX-RS 서비스를 MVC 템플릿에 연결할 수 없습니다.

java.io.IOException: The template name, /view, could not be resolved to a fully qualified template name 

http://localhost:8080/myproject/foos 결과를.

무엇이 누락 되었습니까?

리소스 :

package resources; 

import com.sun.jersey.api.view.Viewable; 
import javax.ws.rs.GET; 
import javax.ws.rs.Path; 
import javax.ws.rs.PathParam; 
import javax.ws.rs.Produces; 
import javax.ws.rs.core.MediaType; 

@Path("foos") 
public class FooResource { 

    @GET 
    @Produces(MediaType.TEXT_HTML) 
    public Viewable get() { 

     return new Viewable("/index", this); 

    } 

    @GET 
    @Path("{id}") 
    @Produces(MediaType.TEXT_HTML) 
    public Viewable get(@PathParam("id") String id) { 

     return new Viewable("/view", id); 

    } 

} 

조회수 :/JSP/자원/FooResource

  • 을 View.jsp
  • 웹 index.jsp를

    • WEB-INF .xml :

      <?xml version="1.0" encoding="UTF-8"?> 
      <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
      
          <filter> 
           <filter-name>jersey</filter-name> 
           <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class> 
           <init-param> 
            <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name> 
            <param-value>/(resources|images|js|styles|(WEB-INF/jsp))/.*</param-value> 
           </init-param> 
          </filter> 
      
          <filter-mapping> 
           <filter-name>jersey</filter-name> 
           <url-pattern>/*</url-pattern> 
          </filter-mapping> 
      
          <servlet> 
           <servlet-name>ServletAdaptor</servlet-name> 
           <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> 
           <init-param> 
            <description>Set the default, base template path to the WEB-INF folder.</description> 
            <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name> 
            <param-value>/WEB-INF/jsp</param-value> 
           </init-param> 
           <load-on-startup>1</load-on-startup> 
          </servlet> 
      
          <servlet-mapping> 
           <servlet-name>ServletAdaptor</servlet-name> 
           <url-pattern>/*</url-pattern> 
          </servlet-mapping> 
      
          <session-config> 
           <session-timeout> 
            30 
           </session-timeout> 
          </session-config> 
      
      </web-app> 
      

    답변

    5

    만들어 다음과 같이 변경 :

    의 web.xml :

    <?xml version="1.0" encoding="UTF-8"?> 
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> 
        <session-config> 
         <session-timeout>30</session-timeout> 
        </session-config> 
    
        <welcome-file-list> 
         <welcome-file>welcome.jsp</welcome-file> 
        </welcome-file-list> 
    
        <filter> 
         <filter-name>jersey</filter-name> 
         <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class> 
         <init-param> 
          <param-name>com.sun.jersey.config.property.packages</param-name> 
          <param-value>controllers</param-value> 
         </init-param>   
         <init-param> 
          <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name> 
          <param-value>/((WEB-INF/views))/.*</param-value> 
         </init-param> 
         <init-param> 
          <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name> 
          <param-value>/WEB-INF/views/</param-value> 
         </init-param> 
         <init-param> 
          <param-name>com.sun.jersey.config.feature.Redirect</param-name> 
          <param-value>true</param-value> 
         </init-param> 
         <init-param> 
          <param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name> 
          <param-value>true</param-value> 
         </init-param>   
        </filter> 
        <filter-mapping> 
         <filter-name>jersey</filter-name> 
         <url-pattern>/*</url-pattern> 
        </filter-mapping> 
    
    </web-app> 
    

    리소스 :

    @Path("foos") 
    public class FooResource { 
    
        @GET 
        @Produces(MediaType.TEXT_HTML) 
        public Viewable index() { 
    
         return new Viewable("/foos/index", this); 
    
        } 
    
        @GET 
        @Path("{id}") 
        @Produces(MediaType.TEXT_HTML) 
        public Viewable view(@PathParam("id") String id) { 
    
         return new Viewable("/foos/view", id); 
    
        } 
    
    } 
    

    조회수 :

    • \ 위해 welcome.jsp
    • \ WEB-INF \ 전망 \ FOOS 내가 부두 9 응용 프로그램에서 실행이 같은 오류가 발생했다 index.jsp를
      • 을 View.jsp
    0

    초기 검사에서 index.jsp와 view.jsp를 WEB-INF/jsp에 직접 넣으려고한다고 생각합니다.

    0

    이름은 /index.jsp 또는 /index.html과 같은 정규화 된 이름이어야합니다.

    1

    \ 잘 가 MVN 깨끗하고 사용 달렸다 jetty :을 실행했는데 전쟁으로 포장되어 Jetty에 배치되면이 오류가 발생합니다. 이것은 나를 위해 일한 web.xml의 수정입니다 :

      <init-param> 
          <param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name> 
    -   <param-value>/WEB-INF/views/</param-value> 
    +   <param-value>/WEB-INF/views</param-value> 
         </init-param> 
    

    그래, 그게 다예요. 그래서, 이것은 누군가가이 문제에 걸려 넘어지면 도움이됩니다. 내 구성은 기본적으로 craig와 동일하지만 추가 슬래시가 있습니다.

    관련 문제