Why not find the servlet?

The first example get 404 can not find, like Toko to change this code (1.bottom) + web.xml ..

There is an appeal for: localhost:8080/Testing/register/get when you download servera..

Use IDEA - here is an example of nastroek:

198d6686a5eb4bfcb13750884200ada3.png08be67bf796f4b04ae5c0fa5051effb9.png

my 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>


1.
@Path("/register")
public class JerseyDemo {


@GET
@Path("/get")
 public String getValue(@QueryParam("value") String value){

 System.out.println("The Value is: "+value); // will have null output ! 

 return value;
}
}


The second example works, create a web.xml there Is an appeal for: localhost:8080/Testing/register
2.
@WebServlet(mapping includes = "/register")
public class JerseyDemo extends HttpServlet{

@Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
 // code working
}
}


Tomcat localhost log:
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.the run(ThreadPoolExecutor.java:617)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.lang.Thread.run(of the Thread.java:745)


Changed to: when you start the server request to URL: localhost:8080/Testing/jersey/register/get
public class ApplTest {

 public static void main(String[] args) {

 Client Client = a clientbuilder produces.newClient();

 Response request = client.target("http://localhost:8080/Testing/jersey/register/get").request().get();

System.out.println(request);
}
}


InboundJaxrsResponse{context=clientresponse, which{method=GET, uri=localhost:8080/Testing/jersey/register/get, status=404, reason=Not Found}}

@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>
July 2nd 19 at 17:50
1 answer
July 2nd 19 at 17:52
1) Define or mapping on web.xml or use annotations in the servlets.
Simultaneously bind a single servlet to one address of the annotation, and web.xml - not what he was arguing.

2) the Annotation Path("/register") and Path("/get")
talking about Urla: @application_name@/register/get
what a magical way of tomkat must decide about the appearance of the jersey?

3) web.xml with jersey describes the url: /jersey/get not /jersey/register/get
Tutorials 10 - 13, I don't know what I'm doing wrong .. https://www.youtube.com/watch?v=2QD1sOG8pyU&index=...

3) web.xml with jersey describes the url: /jersey/get not /jersey/register/get ??
/jersey/* means that after @application_name or context@/jersey/*(I can turn to any resource) .. isn't it ?

1) Define or mapping on web.xml or use annotations in the servlets - Yes, I decided I just and so and so tried .. If you take unasledovala from HttpServlet it work If you use Jersey Servlet Container approach the problem. - stephon_Abshire commented on July 2nd 19 at 17:55
:
3) register/jersey/*
Just means that the url starts with /jersey/ servlet will be invoked, which in web.xml the assigned register name ie org.glassfish.jersey.servlet.ServletContainer.
* - means only that on can be the parameters for the query. - rodolfo_MacGyv commented on July 2nd 19 at 17:58
: I do NOT understand what you want to convey to me completely. I wrote the servlets normal and everything works. I tried to write with all Jesery does not mood.. As in my case, to write correctly ? - stephon_Abshire commented on July 2nd 19 at 18:01
: I beg your pardon, I hunted it seems, looked - according to the paths presented in web.xml and JerseyDemo should respond
/jersey/register/get

However, in the section:
see: jersey.config.server.provider.packages
and should be: com.sun.jersey.config.property.packages - rodolfo_MacGyv commented on July 2nd 19 at 18:04
: com.sun.jersey.config.property.packages if it is a different version to use, below 2.0 as far as I know.. and if you prepustite this code yourself and run it you will have to work with ? If Yes then give a list of your jars.. I think the problem in this.. - stephon_Abshire commented on July 2nd 19 at 18:07
: I'll try, but I'm not sure, a few other requirements: to work even on "the microwave", so recently the current has been updated to Tomcat 6 and api 2.5 - rodolfo_MacGyv commented on July 2nd 19 at 18:10

Find more questions by tags Java EEJavaTomcatJava servlets