使用 Jersey 的 REST with Java (JAX-RS) 中的欢迎页面 [英] Welcome page in REST with Java (JAX-RS) using Jersey
本文介绍了使用 Jersey 的 REST with Java (JAX-RS) 中的欢迎页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Jersey 实现一个 Restful Web 服务.我想将 index.jsp 显示为欢迎页面.
I am implementing a Restful Web Service using Jersey. I want to show index.jsp as welcome page.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Rest Page</title>
</head>
<body>
<h1>Rest is working!</h1>
</body>
</html>
当我在 web.xml 中使用此代码时,它工作正常:
It works fine when I use this code in my web.xml:
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/whatever/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
问题是当用户模式是这样的时候:
The problem is when the user-pattern is like this:
<url-pattern>/*</url-pattern>
除了欢迎页面,一切正常.我感谢任何帮助.
Everything works fine except welcome page. I appreciate Any help.
推荐答案
我找到了另一种方法来做到这一点.而不是使用 index.jsp,我可以使用如下类:
I found an alternative way to do this. instead of using index.jsp, I can use a class like:
@Path("/")
public class Hello {
// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello() {
return "<html> " + "<title>" + "Rest Page" + "</title>"
+ "<body><h1>" + "REST is Working!" + "</body></h1>" + "</html> ";
}
在 web.xml 中我不需要使用:
In web.xml I do not need to use:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
它适用于:
<url-pattern>/*</url-pattern>
这篇关于使用 Jersey 的 REST with Java (JAX-RS) 中的欢迎页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文