无法将 JAX-RS 服务连接到 MVC

我正在尝试使用 JAX-RS' (Jersey) MVC 模式。尝试访问http://localhost:8080/myproject/foos/test 会导致错误如下:

java.io.IOException:模板名称/view无法解析为完全限定的模板名称

http://localhost:8080/myproject/foos 会导致同样的错误。

我错过了什么?

资源:

打包资源;导入com.sun.jersey.api.view.Viewable;导入javax.ws.rs.GET;导入javax.ws.rs.Path;导入javax.ws.rs.PathParam;导入javax.ws.rs.Produces;导入javax.ws.rs.core.MediaType;@Path( "foos" )公共 类 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);    }}

意见:

WEB-INF/jsp/资源/FooResource

  • 索引.jsp
  • 视图.jsp

网页.xml:

<? xml 版本 = “1.0”编码 = “UTF-8” ?> < web-app 版本= “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" >    <过滤器>         <过滤器名称>球衣         <过滤器类> com.sun.jersey.spi.container.servlet.ServletContainer          <初始化参数>             <参数名称> com .sun.jersey.config.property.WebPageContentRegex              < param-value > /(resources|images|js|styles|(WEB-INF/jsp))/.*                   < filter-mapping >         < filter-name > jersey          < url-pattern > /*          < servlet >         < servlet-name > ServletAdaptor          < servlet-class > com.sun.jersey.spi.container.servlet.ServletContainer          < init-param >             < description >设置默认, WEB-INF 文件夹的基本模板路径。             <参数名称> com.sun.jersey.config.property.JSPTemplatesBasePath              <参数值> /WEB-INF/jsp <参数值>                  < load-on-startup > 1          < servlet-mapping >         < servlet-name > ServletAdaptor          < url-pattern > /*          <会话配置>         <会话超时>            30             

进行了以下更改:

网页.xml:

<? xml 版本 = “1.0”编码 = “UTF-8” ?> < web-app 版本= “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          < welcome-file-list >         < welcome-file > welcome.jsp          <过滤器>         <过滤器名称>球衣         <过滤器类> com.sun.jersey.spi.container.servlet.ServletContainer          <初始化参数>             <参数名称> com .sun.jersey.config.property.packages              < param-value >控制器                  < init-param >             < param-name >com.sun.jersey.config.property.WebPageContentRegex              < param-value > /((WEB-INF/ views))/.*                   < init-参数>             <参数名称> com.sun.jersey.config.property.JSPTemplatesBasePath              <参数值> /WEB-INF/views/                   < init -param >             <参数名称>com.sun.jersey.config.feature.Redirect              < param-value > true                   < init-param >             < param-name > com.sun.jersey .config.feature.FilterForwardOn404              < param-value > true                    < filter-mapping >         < filter-name >球衣         < url-pattern > /*      

资源:

@Path ( "foos" )公共类 FooResource {    @GET     @Produces (MediaType.TEXT_HTML)    公共可视索引(){        返回 新的 可视(“/foos/index”,this);    }       @GET @Path ( "     { id }" )@Produces ( MediaType.TEXT_HTML)     public     Viewable view ( @PathParam ( "id" ) String id) {          返回 新的 可视(“/foos/view”,id);    }}
JAX
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章