Re: Java Applet can not communicate with Java Servlet
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Chuck, On 4/29/13 11:20 AM, Caldarale, Charles R wrote: >> From: Christopher Schultz [mailto:ch...@christopherschultz.net] >> Subject: Re: Java Applet can not communicate with Java Servlet > >> The servlet spec says that all servlets need to be in a package. > > No, it doesn't - but it's still a good idea. Hrm, I thought that was in the servlet spec, but it's definitely not. Still a good idea and probably should be treated by most people as a soft requirement. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJRf86jAAoJEBzwKT+lPKRYoC4QAIheShUhLc6mBGQHXcD2VleD iE3peJwlYdXwho2xN8vWz9gXuHBLzJFrLyHOLKqZoD0d7q+dVyg2S4drBb83TP5V +XYjizHlNT66E7kxUmNpUs9sVDXznmtJdr68jXkvFSi65k5FOvHYoWZifKfsoTWs Rq42kGu4lJfvanyQF4brPtCrJO8DJT8N9mF0RhdBK3Eb4M5fVWuR35ckhHWKOI7p +Qq9BcM+hxTAGQodjkM4b0TEJMFfWhzh8lknc4yzZww/Xh+hUl0vj+NndCHJjC4K k7jV2vnQXcz0dMJpZG762jrkKxxAIPzmd1IEMQ1iA2bHv3EXOUrnmp3G4Uv/do/I 1eDM4exF7c7kGsESvStwko5uAcHioGuutTJ1b+vh/XzHo0+l3bXKiWXntb3qZvQz xwOkB4sHghAWuxEhVdbqVZYsAX05fNBB//S+U4kv19qlLBtSWuT1PaUZ0cDFgNFc bX6DrPnYypYRBHH2E5JYz8OI3O2ZVFHEaKSCoY6tHFvo1moyJ4QZ7lbxVojUf1ZP yewFm8nQuQrSkpMEsUHGJ1iSiH5VS1C4jtTglRTQW52kYFx504rIeIIf3QxT5IwI eOwlF0eNRH+hWvvYebg3cZTtMNDZdr06Uh8LAoW31awLtJwJvehNsZDYwrA60kNM 3l4YYqwavu6TMN7RFLRx =w4tx -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: Java Applet can not communicate with Java Servlet
> From: Christopher Schultz [mailto:ch...@christopherschultz.net] > Subject: Re: Java Applet can not communicate with Java Servlet > The servlet spec says that all servlets need to be in a package. No, it doesn't - but it's still a good idea. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Java Applet can not communicate with Java Servlet
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Peng, On 4/29/13 10:05 AM, qingtao peng wrote: > uc.setRequestProperty("Content-type","application/xwww-form-urlencoded"); I > think you want: application/x-www-form-urlencoded > res.setContentType("text/html;charset=GB2312"); Why not use UTF-8 like you did in the Applet? What you have done is not wrong and it should work, but it does seem a little odd to use different character encodings in different places. > I have started the apache-tomcat-7.0.32 server ,then I have typed > the network address of DbApplet.htm in the address field of the > browser.I click on the button in the Applet,but receive > java.io.FileNotFoundException error.The error is > java.io.FileNotFoundException: > http://localhost:8080/Servlet/DbServlet.Where do I place DbServlet > ? The servlet spec says that all servlets need to be in a package. So you should have a "package" statement at the top of your .java file, then re-compile. > That is, which directory do I place under in > apache-tomcat-7.0.32. Assuming your package is "my.pkg", then you want your .class file here: .../mywebapp/WEB-INF/classes/my/pkg/DbServlet.class > What is the network address of this Servlet .I thank for helps. Network address (hostname) will be wherever you configured Tomcat to listen (localhost? www.foo.com?). The URL will depend upon how you have mapped the servlet in web.xml. Have you done that? - -chris -BEGIN PGP SIGNATURE- Version: GnuPG/MacGPG2 v2.0.17 (Darwin) Comment: GPGTools - http://gpgtools.org Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQIcBAEBCAAGBQJRfotFAAoJEBzwKT+lPKRYOLMP/0XuXo5m06m6cXUfv90Ngh+U Vpy4L9y8WCWpHthtJqxk4EDRLT1K0Y5hV6cW0S7BzeH9ynh2VaKVvcWMR3KPcwts Pc60/TUMj7qGLzXkTfBxxUnWGzY6fQLq4KRJdiHDQvycnw/KwYbM1FjDU9PjG2vi yeEZQhEqMrP+fHCq8bYLAH+nuqngIGt59HGlN+1Umz5rsguSu6uq/ymaXUYEzyXZ k1lqDwKSTGn7x4LD+AOqzJxH549bMjFVqexE5Fw4yFCfxChAP7zQwnDhL1jkKcsB TXZJKQ5wNqQmHYg/C/9Cf+jKg7wmF6nEyw3FB4zDcYhKnGXaBBq2S8zF61Y8wKq3 QPkbyMfC8zPivXC1Jx28TyDJVQ81SLyKGB9JYfLZSuGvpN3rEV5sXOVrwKZw4+D7 mRYrwCYshm2/ueFALPXEjZbbAQHiXSqISDSdiMxYbIazMOCgxwcWcBfh7Rd2/g5+ rWU/xDdM0rUaIEkRVfA5bVQg9zNOqqoZFe7aEFNlBK0Y02LY2G9Bi2VtrfVMVnHo gXxf0efIn7fyI9ajsh1JFm/f+NxKvZissEPqDRr7pWV0qyqcr8YfErrPT6jYMPl9 lGSF2RIFXO2zaxJ2x6pwnLxWl/EYXxayFPqoCQXTw3lBRLaCeVG+Ftw+l8ni+Gm7 aIzoBlfT46MVINdwePvB =UAT7 -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Java Applet can not communicate with Java Servlet
André Warnier wrote: qingtao peng wrote: I have built the apache-tomcat-7.0.32 server on my computer.My operating system is Windows7.I have written an Applet and compiled it .The source code of the Applet is as follow : ... This compiled Applet has been embedded in a HTML file named with DbApplet.htm. The source code of the Servlet is as follow : ... I have started the apache-tomcat-7.0.32 server ,then I have typed the network address of DbApplet.htm in the address field of the browser.I click on the button in the Applet,but receive java.io.FileNotFoundException error.The error is java.io.FileNotFoundException: http://localhost:8080/Servlet/DbServlet.Where do I place DbServlet ? That is, which directory do I place under in apache-tomcat-7.0.32. What is the network address of this Servlet .I thank for helps. Hi. Simplify the problem. 1) In your HTML page, there is the tag that retrieves the applet from the server. What is the URL from which the applet is being retrieved ? 2) if it is like "/Servlet/DbServlet", then the .jar file in which your compiled applet is embedded, should be in the directory "(tomcat-install-dir)/webapps/Servlet/". 3) if it is indeed a .jar file, then it should be the file "(tomcat-install-dir)/webapps/Servlet/DbServlet.jar" and you should be able to retrieve it if you enter the following URL in your browser's URL bar : "http://localhost:8080/Servlet/DbServlet.jar"; (The browser will probably ask you where to save that file, it will not run it in this case). Note: when the browser has retrieved your HTML page from the server, it sees the applet tag in the HTML page. It then makes another request to the server, to retrieve the applet from the server in exactly the same way as if this was for example an image from an tag. It is only after it has retrieved the applet, that the browser will activate its Java run-time machine, to actually run the applet. --- Sorry, it looks like I misunderstood the issue above. From what you write, it seems that the applet is being loaded by the browser - since you can click on "it's button". So you are getting a "java.io.FileNotFoundException error". Where do you get that error message ? in the browser page returned by the server when you click on the applet button ? If so, then it is your servlet (on the server side) that is getting that error. And then /you/ have to find out why it is getting that error. There would be nothing wrong with Tomcat. It is your application which makes the error happen. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Java Applet can not communicate with Java Servlet
qingtao peng wrote: I have built the apache-tomcat-7.0.32 server on my computer.My operating system is Windows7.I have written an Applet and compiled it .The source code of the Applet is as follow : ... This compiled Applet has been embedded in a HTML file named with DbApplet.htm. The source code of the Servlet is as follow : ... I have started the apache-tomcat-7.0.32 server ,then I have typed the network address of DbApplet.htm in the address field of the browser.I click on the button in the Applet,but receive java.io.FileNotFoundException error.The error is java.io.FileNotFoundException: http://localhost:8080/Servlet/DbServlet.Where do I place DbServlet ? That is, which directory do I place under in apache-tomcat-7.0.32. What is the network address of this Servlet .I thank for helps. Hi. Simplify the problem. 1) In your HTML page, there is the tag that retrieves the applet from the server. What is the URL from which the applet is being retrieved ? 2) if it is like "/Servlet/DbServlet", then the .jar file in which your compiled applet is embedded, should be in the directory "(tomcat-install-dir)/webapps/Servlet/". 3) if it is indeed a .jar file, then it should be the file "(tomcat-install-dir)/webapps/Servlet/DbServlet.jar" and you should be able to retrieve it if you enter the following URL in your browser's URL bar : "http://localhost:8080/Servlet/DbServlet.jar"; (The browser will probably ask you where to save that file, it will not run it in this case). Note: when the browser has retrieved your HTML page from the server, it sees the applet tag in the HTML page. It then makes another request to the server, to retrieve the applet from the server in exactly the same way as if this was for example an image from an tag. It is only after it has retrieved the applet, that the browser will activate its Java run-time machine, to actually run the applet. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org