我正在尝试使用Jersey 2.3在独立的Tomcat中为jsp页面设置一个简单的应用程序.我已经从网上尝试了很多方法,但是他们中的大部分都在使用泽西与Grizzly而不是Tomcat进行解释.所以我找不到解决方案/解释我的问题为什么我的应用程序不提供jsp服务.有人知道这里有什么不对或缺失吗?请在下面找到我的申请表.
的pom.xml
...
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc-jsp</artifactId>
<version>2.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<id>tomcat-run</id>
<goals>
<goal>exec-war-only</goal>
</goals>
<phase>package</phase>
<configuration>
<path>/jhello</path>
<enableNaming>false</enableNaming>
<finalName>jhello-standalone.jar</finalName>
<charset>utf-8</charset>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
web.xml中
<filter>
<filter-name>jhello</filter-name>
<filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.granatasoft.playground.jersey</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.property.WebPageContentRegex</param-name>
<param-value>/(decorators|scripts|styles|resources|(WEB-INF/views))/.*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jhello</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
HelloJersey.java
package com.granatasoft.playground.jersey;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.glassfish.jersey.server.mvc.Viewable;
@Path("/hello")
public class HelloJersey {
@GET …Run Code Online (Sandbox Code Playgroud) 我正在使用版本"5.0.0-rc1"中的"Microsoft.AspNet.WebApi.SelfHost"NuGet包(也试过当前的稳定版),但遗憾的是我无法通过我的应用程序设置来解析配置的路由到我的ApiController的实现.
该应用程序非常简单,几乎可以在所有示例中找到.它包含一个.NET控制台应用程序,其中主要类是自托管服务.
using System.Web.Http.SelfHost;
using System.Web.Http;
using System;
namespace EP.Server
{
class Program
{
static void Main(string[] args)
{
var config = new HttpSelfHostConfiguration("http://localhost:60064");
config.Routes.MapHttpRoute(
name: "Default Route",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
using (var server = new HttpSelfHostServer(config))
{
server.OpenAsync().Wait();
Console.WriteLine("Server ist running on "+config.BaseAddress + " hit ENTER to stop.");
Console.ReadLine();
server.CloseAsync().Wait();
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后有一个单独的控制器类,它位于同一个项目中,并继承自ApiController类.
using System.Web.Http;
namespace EP.Server
{
class UsersController : ApiController
{
[HttpGet]
public string Get()
{
return …Run Code Online (Sandbox Code Playgroud)