gpt4 book ai didi

java - Jersey servlet 映射困惑

转载 作者:行者123 更新时间:2023-11-30 04:01:16 25 4
gpt4 key购买 nike

有人可以用简单的英语解释它是如何工作的(或者至少为什么我的结构不能)?我希望在 Jersey servlet 资源(我将其称为 ExportResource)中有一个名为 ExportLicenseInfo 的函数,以映射到 http://example.com/myApp/export/software_licenses.{year}-{月}.{format},例如:http://example.com/myApp/export/software_licenses_2013-10.csv

web.xml 中的 Servlet 配置:

<servlet>
<servlet-name>ExportServlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>

<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.mycompany.app.ExportApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

我在 web.xml 中的 servlet 映射:

<servlet-mapping>
<servlet-name>ExportServlet</servlet-name>
<url-pattern>/export</url-pattern>
</servlet-mapping>

我的带有 @Path 注释的代码:

@Path("/export")
public class ExportResource {

...

@GET
@Produces({"text/csv", "application/json"})
@Path("/software_licenses_{year: [0-9][0-9][0-9][0-9]}-{month: [0-1][0-9]}.{format}")
public String ExportLicenseInfo( ... ) {
...
}

当我尝试访问资源时,我收到 404.Jersey 跟踪日志:

Feb 21, 2014 2:41:46 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 6 * LoggingFilter - Request received on thread http-bio-8080-exec-67
6 > GET http://localhost:8080/app/export/software_licenses_2013-10.csv
6 > host: localhost:8080
6 > connection: keep-alive
6 > cache-control: max-age=0
6 > accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
6 > user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36
6 > accept-encoding: gzip,deflate,sdch
6 > accept-language: en
6 > cookie: JSESSIONID=DB64E0B066BDEE8CABFC94686AD6ACDC.test; JSESSIONIDSSO=61B51CEED61F8F6CE8A8DB46B38BAC9F; i18next=en

Feb 21, 2014 2:41:46 PM org.glassfish.jersey.filter.LoggingFilter log
INFO: 6 * LoggingFilter - Response received on thread http-bio-8080-exec-67
6 < 404

最佳答案

尝试像这样映射 Jersey servlet:

<servlet-mapping>
<servlet-name>ExportServlet</servlet-name>
<url-pattern>/export/*</url-pattern>
</servlet-mapping>

关于java - Jersey servlet 映射困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21946520/

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