我正在尝试使用 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
网页.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-name > < param-value > /(resources|images|js|styles|(WEB-INF/jsp))/.* param-value > 初始化参数> 过滤器> < 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 >设置默认, WEB-INF 文件夹的基本模板路径。描述> <参数名称> com.sun.jersey.config.property.JSPTemplatesBasePath 参数名称> <参数值> /WEB-INF/jsp <参数值> init-param > < load-on-startup > 1 load-on-startup > servlet > < servlet-mapping > < servlet-name > ServletAdaptor servlet-name > < url-pattern > /* url-pattern > servlet-mapping > <会话配置> <会话超时> 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 session-timeout > session-config > < welcome-file-list > < welcome-file > welcome.jsp welcome-file > welcome-file-list > <过滤器> <过滤器名称>球衣过滤器名称> <过滤器类> com.sun.jersey.spi.container.servlet.ServletContainer 过滤器类> <初始化参数> <参数名称> com .sun.jersey.config.property.packages param-name > < param-value >控制器 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-参数> <参数名称> com.sun.jersey.config.property.JSPTemplatesBasePath 参数名称> <参数值> /WEB-INF/views/ 参数值> init-param > < init -param > <参数名称>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 >球衣 < url-pattern > /* url-pattern > filter-mapping >网络应用>资源:
@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); }} | 留言与评论(共有 0 条评论) “” |