gpt4 book ai didi

java - 从哪里获取 javax.servlet.http.annotation 包?

转载 作者:行者123 更新时间:2023-12-02 00:06:01 25 4
gpt4 key购买 nike

代码如下:

package de.swt1321.servlet;

import java.io.OutputStream;

import javax.servlet.http.annotation.Servlet;
import javax.servlet.http.annotation.GET;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Servlet(urlMappings={"/ServletTest"})
public class ServletTest {
private static final java.nio.charset.Charset UTF8 = java.nio.charset.Charset.forName("UTF8");
@GET
public void handleGet(HttpServletRequest req,
HttpServletResponse res)
{
byte[] HTML = "<html><head><title>Hello World!</title></head><body><h1>IT WORKED!</h1></body></html>".getBytes(UTF8);
res.setStatus(HttpServletResponse.SC_OK);
res.setHeader("content-type","text/html;charset=utf8");
res.setIntHeader("content-length",HTML.length);
OutputStream os = res.getOutputStream();
os.write(HTML);
os.flush();
}
}

我希望这能根据 this 工作,不幸的是,到目前为止我还无法找到包含 javax.servlet.http.annotation 包的 jar。我从 http://download.java.net/maven/2 中查看了“javax:javaee-api:jar:6.0”以及 Jetty 9 附带的 servlet-api-3.0.jar 中,但到目前为止还没有运气。我有点没有想法,我错过了什么?

到目前为止,我正在构建/尝试使用此 Builder 构建文件进行构建:

# Version number for this release
VERSION_NUMBER = "1.0.0"
# Group identifier for your projects
GROUP = "swt1321"
COPYRIGHT = ""

# Specify Maven 2.0 remote repositories here, like this:
repositories.remote << "http://repo1.maven.org/maven2"

# This really bugs me, this isn't only supposed to build on my own PC after all!
# But as I said, the one at the download.java.net repo didn't work
JAVA_EE_PATH = "/home/hannes/Lib/Java/jetty-distribution-9.0.0.M3/lib/servlet-api-3.0.jar"
java_ee = artifact("de.swt1321:java_ee:jar:1.0").from(file JAVA_EE_PATH)

project_layout = Layout.new
project_layout[:source,:main,:java] = 'src'
project_layout[:source,:test,:java] = 'test'

desc "The Servlettest project"
define "ServletTest", :layout => project_layout do
project.version = VERSION_NUMBER
project.group = GROUP
manifest["Implementation-Vendor"] = COPYRIGHT
compile.with java_ee
package :war
end

最佳答案

这个包是servlet-api.jar的子包,你可以在容器的lib文件夹中找到这个jar文件。对于 tomcat 来说是[tomcat安装目录]->lib->servlet-api.jar

关于java - 从哪里获取 javax.servlet.http.annotation 包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13867879/

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