質問

I am trying to demo simple Ajax/Servlet request.For this i have created a new Dynamic web project in eclipse and added a simple Servlet to take the request and present the same back to UI. I have included my Servlet details in web.xml. I am using Tomcat as my server. No Build scripts yet(i felt not needed at this point)

Servlet Code:

response.setContentType("text/html");
    PrintWriter out =response.getWriter();
    String txt = request.getQueryString();
    out.println(txt);

Js Code:

$(function(){
        $.get('/jirarequest','OK',function(op){
            $('#maindiv').appendTo(op);
        });

    });

Html Code:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Jira-Synchronization</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>JiraSyncServlet</servlet-name>
    <servlet-class>src.JiraSyncServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>JiraSyncServlet</servlet-name>
    <url-pattern>/jirarequest/*</url-pattern>
</servlet-mapping>

My Project structure:enter image description here

My HTML:

enter image description here

I am getting a error in Fire bug saying

"NetworkError: 404 Not Found - http://localhost:8080/jirarequest?OK"

The URL i am using in browser is http://localhost:8080/Jira-Synchronization/index.html. i have double checked all kind of typo. I debugged by putting breaking point but the debugger never hit my Servelt. I am not sure what is wrong? URL is wrong or wiring is wrong or the way it set up something is missing?

役に立ちましたか?

解決

Some info:

  • The 404 error means Tomcat doesn't have any file or servlet or anything exposed for serving at that URL path.

  • The 500 error means Tomcat has a servlet (or jsp) exposed at that URL path and an unexpected exception was generated while trying to run the java code.

Collection of things we know need to be changed:

  $.get('/jirarequest/whatever','OK',function(op){

and

<servlet>
    <servlet-name>JiraSyncServlet</servlet-name>
    <servlet-class>JiraSyncServlet</servlet-class>
</servlet>

Plus you can test in the browser by typing this URL which should return OK:

http://localhost:8080/Jira-Synchronization/jirarequest/whatever?OK
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top