这里的代码:
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以及Jetty 9 附带的“javax:javaee-api:jar:6.0” servlet-api-3.0.jar
,但到目前为止还没有运气。我在这里有点想法,我错过了什么?
到目前为止,我正在构建/尝试使用此 Buildr 构建文件进行构建:
# 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