Answer the question
In order to leave comments, you need to log in
Why can't find the servlet?
The first example I get 404 does not find, how do I change it to this code (1.bottom) + web.xml ..
There is a call to: localhost:8080/Testing/register/get when loading the server .. I
use IDEA - I give an example settings:
mine web.xml:
<servlet>
<servlet-name>register</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>demo.JerseyDemo</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>register</servlet-name>
<url-pattern>/register/*</url-pattern>
</servlet-mapping>
@Path("/register")
public class JerseyDemo {
@GET
@Path("/get")
public String getValue(@QueryParam("value") String value){
System.out.println("The Value is: "+value); // will have output null !
return value;
}
}
@WebServlet(urlPatterns = "/register")
public class JerseyDemo extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// code working
}
}
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1100)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:687)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
public class ApplTest {
public static void main(String[] args) {
Client client = ClientBuilder.newClient();
Response request = client.target("http://localhost:8080/Testing/jersey/register/get").request().get();
System.out.println(request);
}
}
@Path("/register")
public class JerseyDemo {
@Context
HttpServletResponse httpServletResponse;
@GET
@Path("/get")
public void testServlet() throws IOException {
httpServletResponse.getWriter().print("Hello");
System.out.println("Hello!");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>register</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>demo</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>register</servlet-name>
<url-pattern>/jersey/*</url-pattern>
</servlet-mapping>
</web-app>
Answer the question
In order to leave comments, you need to log in
1) Be defined, or mapping on web.xml or annotations in servlets.
It is impossible to bind one servlet to one address from annotations and web.xml at the same time, which he cursed about.
2) Annotations Path("/register") and Path("/get")
say about the url: @[email protected]/register/get
how magically Tomcat should decide about jersey appearance?
3) web.xml with jersey describes url: /jersey/get, not /jersey/register/get
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question