Jump to content

Problem with Java Servlet and JavaScript communication

Recommended Posts

I'm trying to make a XMLHttpRequest from a JavaScript page to a Java Servlet.I found out lots of problem because it's first time that I do this. The main problem it's that the servlet doesn't work!It give me this error:

HTTP Status 500 - Servlet execution threw an exception type: Exception report message: Servlet execution threw an exception description: The server encountered an internal error that prevented it from fulfilling this request. exception: javax.servlet.ServletException: Servlet execution threw an exceptionroot cause java.lang.NoClassDefFoundError: com/google/appengine/api/channel/ChannelServiceFactoryProvaServer.Server.doPost(Server.java:30)javax.servlet.http.HttpServlet.service(HttpServlet.java:647)javax.servlet.http.HttpServlet.service(HttpServlet.java:728)root cause java.lang.ClassNotFoundException: com.google.appengine.api.channel.ChannelServiceFactoryorg.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)ProvaServer.Server.doPost(Server.java:30)javax.servlet.http.HttpServlet.service(HttpServlet.java:647)javax.servlet.http.HttpServlet.service(HttpServlet.java:728) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.33 logs.

This is the Java Servlet code:

package ProvaServer; import java.lang.Object;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.google.appengine.api.channel.*;import com.google.appengine.api.channel.ChannelServiceFactory; @WebServlet(description = "prova", urlPatterns = { "/provaFinale" })public class Server extends HttpServlet {	  private static final long serialVersionUID = 1L;		 public Server() {		  super();		  // TODO Auto-generated constructor stub	 } 	 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {		  String userId = request.getParameter("idUser"); 		  ChannelService channelService = ChannelServiceFactory.getChannelService();      //the problem is here! 		  String token = channelService.createChannel(userId); 		  System.out.println("IdUser:" + userId);  		  System.out.println("Token:" + token); 		  String url="mona.html?user="+userId+"&token="+token;		  response.sendRedirect(url);	 } 	 @Override	 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {}}

and this is the web.xml servlet mapping file:

<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">	<display-name>Server</display-name>	<welcome-file-list>		<welcome-file>index.html</welcome-file>	</welcome-file-list>	<servlet>		<servlet-name>ServerServlet</servlet-name>		<servlet-class>ProvaServer.Server</servlet-class>	</servlet>   <servlet-mapping>		<servlet-name>ServerServlet</servlet-name>		<url-pattern>/provaFinale</url-pattern>   </servlet-mapping></web-app>

The problem come out when servlet try to run this code: ChannelService channelService = ChannelServiceFactory.getChannelService() but i can't understand what is the error.Could someone help me to understand? :)Thanks for the attention!

Edited by RikyTres

Share this post

Link to post
Share on other sites

Thanks for the answer, but I tried a lot and I wasn't able to do this, then i change way...Now I use WebSocket and everything works fine!

Share this post

Link to post
Share on other sites

Hi finding alternative or leaving it because you have not understood, is not going to help you in the long run. The problem is with "com.google.appengine.api.channel.ChannelServiceFactory" . This is not part of j2ee spec. This is from a third party. So do u have the jar file which contains this class. I think you should be able to get it from google as the name appears. Get the jar file and keep that in the "lib" folder which will be in the "web-inf" folder of your app. Hope this helps.

  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...