gpt4 book ai didi

java - Jersey (jsr 311)和自定义 ViewProcessor

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:41:19 25 4
gpt4 key购买 nike

我似乎无法全神贯注于如何在 Jersey 中实现自定义 ViewProcessor。我有以下资源:

@Path("/events")
public class EventController extends AbstractController {
private static final Logger LOG = LoggerFactory.getLogger(EventController.class);

@Resource(name = "eventService")
private EventService eventService;

public void setEventService(EventService eventService) {
this.eventService = eventService;
}

@GET
@Produces(MediaType.TEXT_HTML)
public Viewable viewEventsAsHtml() {
Map<String, String> model = new HashMap<String, String>();
model.put("msg", "test");
return new Viewable("/events.jsp", model);
}
}

因为我想在“/WEB-INF/views/jsp”中组织我的 jsp View ,所以我扩展了 JSPTemplateProcessor:

public class CJJspTemplateProcessor extends JSPTemplateProcessor {
private static final Logger LOG = LoggerFactory.getLogger(CJJspTemplateProcessor.class);

private final String basePath = "/WEB-INF/views/jsp";

public CJJspTemplateProcessor(@Context ResourceConfig resourceConfig) {
super(resourceConfig);
}

@Override
public String resolve(String name) {
String path;
if (!name.endsWith(".jsp")) {
name += ".jsp";
}
path = basePath + name;
LOG.debug("resolving " + name + " to " + path);
return path;
}
}

但是当我导航到事件资源时,我得到了一个 404,尽管我可以看到 TemplateProcessor 为日志文件中的 jsp 解析了正确的路径。

求助:)

最佳答案

您不需要自定义 TemplateProcessor 来执行此操作,只需将以下内容添加到您的 web.xml 中的过滤器元素即可。

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

关于java - Jersey (jsr 311)和自定义 ViewProcessor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2873892/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com