java - Servlets and AJAX communication -
I have a communication problem between my Java sublet and an AJAX request. More about it:
The complete path of index.html (including Javascript / AJAX requests):
Servlet: MyChat.class
in the same folder and the request is working as follows: / P>
var url = "";
var name = document.getElementById ("user name"). GetAttribute ("value"); Var msg = document.getElementById ("Message"). GetAttribute ("value");
var tosend = name + "," + message;
request.open ('GET', URL, true); Request.send (tosend); Request.onreadystatechange = interpretRequest;
I get a form where a username and message are just type and "username" and "messages" are tagged in my html file. I am working AJAX request, it is definite, but this servlet Does not communicate with me, I have no idea where the system is from Output.printlean () output goes out. No log file is loaded ... and the servletlet looks like this:
Public class microlett HTTPServlet {Private fixed final long serial UID = 1L;
Private Arrestists & lt; String & gt; MyMessages = New Array's & lt; String & gt; (); Public Zero doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {BufferedReader R = request.getReader (); While (r.readline ()! = Null) {// '', 'string [] tmp = r.readline (). Divide the divided words on (". \\ s"); MyMessages.add (TMP [0] + "+ + TMP [1]);} //response.setContentType (" text / html "); PrintWriter out = response.getWriter (); Iterator & lt; string & gt; = MyMessages.iterator (); while (this haas next ()) {out.println (it.next ()); println (it.next ());}} throws IOException to public zero doPost (HttpServletRequest request, HttpServletResponse response) ServletException {doGet} (request, response);} }
The URL you specified isn '
Just like the URL of the index page, http: //
file related to the & lt; Resources & gt;
section of the & gt; URL is required.
For example, if you had a controller servlet, you would expect the following in your web. Xml:
& lt; servlet & gt; & lt; servlet-name & gt; Admin & lt; / servlet-name & gt; & Lt; Servlet category & gt; ControllerServlet & lt; / Servlet category & gt; & Lt; / Servlet & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; Controller & lt; / Servlet-name & gt; & Lt; URL pattern & gt; / * do. & Lt; / Url pattern & gt; & Lt; / Servlet-mapping & gt;
The URLs that will be invoked for the 'Controller' servlet, the form http: // < Server & gt ;: & lt; Port & gt; / & Lt; Webapp name & gt; / & Lt. ; Anything & gt; .do
.
Comments
Post a Comment