I am working on a GWT application. The app. is working in dev mode.
I am working on a gwt project and trying to deploy it to Apache Tomcat. I have never used Apache Tomcat before and I am rather new to Java and GWT. My tomcat server seems to be up and running as I see the "If you see this you have succesfully installed Tomcat" on localhost:8080/
After I got Tomcat up and running I used Eclipse GWT Compile to compile my app. I have copied my .html file and .css file + the war folder to C:\apache-tomcat-8.0.15\webapps\MyAPP\
Opening the .html file (file:///C:/apache-tomcat-8.0.15/webapps/PurchaseOrder/PurchaseOrder.html) gives me my ui (login screen), but when making the first RPC call (loggin in) I am getting the error "FailureUnable to initiate the asynchronous service invocation (PurchaseOrderService_Proxy.checkUsernameAndPassword) -- check the network connection"
My thougts are that something is incorrect in my web.xml or my service class
PurchaseOrderService.java
package com.google.gwt.sample.purchaseorder.client;
import java.util.ArrayList;
import java.util.HashMap;
import com.google.gwt.sample.purchaseorder.client.model.Brands;
import com.google.gwt.sample.purchaseorder.client.model.Item;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
#RemoteServiceRelativePath("exampleservice")
public interface PurchaseOrderService extends RemoteService {
boolean checkUsernameAndPassword(String value, String value2);
ArrayList<Item> getPersonalInfo();
HashMap<String, ArrayList<Item>> getListOfPurchaseOrderSortedFromBrands();
String createExcelExportFile(HashMap<String, ArrayList<Item>> exportMap);
}
web.xml:
<!-- Servlets -->
<servlet>
<servlet-name>purchaseOrderServiceImpl</servlet-name>
<servlet-class>com.google.gwt.sample.purchaseorder.server.PurchaseOrderServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>purchaseOrderServiceImpl</servlet-name>
<url-pattern>/purchaseorder/exampleservice</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>PurchaseOrder.html</welcome-file>
</welcome-file-list>
</web-app>
Opening the .html file
(file:///C:/apache-tomcat-8.0.15/webapps/PurchaseOrder/PurchaseOrder.html)
gives me my ui (login screen), but when making the first RPC call
(loggin in) I am getting the error "FailureUnable to initiate the
asynchronous service invocation
(PurchaseOrderService_Proxy.checkUsernameAndPassword) -- check the
network connection"
This is not how you access the application running in Tomcat. Your tomcat is running # localhost:8080 so you have to access using http://localhost:8080/<app_context_root>/filename.html
Related
I have installed Apache Tomcat on ubuntu under tomcat directory. I set CATALINA_HOME environment variable for a single session via export. Then I started tomcat from the command line via $CATALINA_HOME/bin/startup.sh. And everything worked well. I saw tomcat official page and assume that the server is installed correctly. Then I created a webb application with a single servlet under
$CATALINA_HOME/webaps/apress/
directory.
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class HelloWorldServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>hello, world</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1> hello world</h1>");
out.println("</body>");
out.println("</html>");
}
}
Then I compiled the file
javac -cp HelloWorldServlet.java -d ./classes -cp $CATALINA_HOME/bin/servlet-api.jar
Compillation was successful and the class file was put into the classes subdirectory of the root directory of the application.
Then I edited web.xml file.
<?xml version ="1.0" encoding ="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns.xsi="http://www.w3.org/2001/XMLSchema-instance"
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>Chapter 2</display-name>
<description> Apress demo</description>
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/hello.html</url-pattern>
</servlet-mapping>
</web-app>
Then I restartd Tomcat. But when I try to access via
http://localhost:8080/apress/hello.html
I get Http status 404 message. What I have done wrong?
I would suggest you first try building your application in an IDE such as Netbeans or Eclipse, then study the configuration files that are automatically generated.
Look in your tomcat directory there is a logs directory. Stop tomcat. Delete all the log files and restart tomcat and hit that URL. Check the logs (mainly access log and catalina.out). Look for errors in there first.
You may also want to consider using #WebServlet instead of editing the web.xml, modern versions of tomcat can identify classes annotated with this and automatically register them as servlets.
#WebServlet(name="HelloWorld", urlPatterns={"/hello.html"})
public class HelloWorldServlet extends HttpServlet {
}
Also, how are you deploying this servlet, as a WAR file?
Two possible things. According to what you wrote, the directory you created the application was:
$CATALINA_HOME/webaps/apress/
It's supposed to be
$CATALINA_HOME/webapps/apress/
But i guess it is just a typeO.
the second thing is that you should copy the compiled file
HelloWorldServlet.class
to
apress/WEB-INF/classes
directory, or directly compile the java file into this directory
I am trying to deploy a compiled Servlet class onto Apache Tomcat server 8.0.30.
But i get the following exception :
javax.servlet.ServletException: Error instantiating servlet class HelloWorld
java.lang.ClassNotFoundException: HelloWorld
My tomcat webapps/ROOT/ folder did not contain the classes folder so i created one and copied HelloWorld.class into it. I added the following lines inweb.xml :
<?xml version="1.0" encoding="ISO-8859-1"?>
<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"
metadata-complete="true">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
Can anyone tell me what am I doing wrong?
#wero : This is the content of my HelloWorld.java :
// Import required java libraries
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Extend HttpServlet class
public class HelloWorld extends HttpServlet {
private String message;
public void init() throws ServletException
{
// Do required initialization
message = "Hello World";
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
// Set response content type
response.setContentType("text/html");
// Actual logic goes here.
PrintWriter out = response.getWriter();
out.println("<h1>" + message + "</h1>");
}
public void destroy()
{
// do nothing.
}
}
You need to put the files into the correct places. Java class files need to be placed into WEB-INF/classes:
webapps/ROOT/WEB-INF/web.xml
webapps/ROOT/WEB-INF/classes/HelloWorld.class
Then start Tomcat and look if there are errors in the Tomcat log.
When tomcat had been started there were not class file in your app. Tomcat is loading classes during deployment on startup or if you manually deploy it at runtime. After that the context should be reloaded. You can't just copy your classes to the tomcat webapps folder without loading them.
Read Tomcat docs how to deploy your application.
Deployment is the term used for the process of installing a web
application (either a 3rd party WAR or your own custom web
application) into the Tomcat server.
Web application deployment may be accomplished in a number of ways
within the Tomcat server:
Statically (the web application is setup before Tomcat is started)
Dynamically (by directly manipulating already deployed web applications (relying on auto-deployment feature) or remotely by using
the Tomcat Manager web application)
The Tomcat Manager is a web application that can be used interactively
(via HTML GUI) or programmatically (via URL-based API) to deploy and
manage web applications.
There are a number of ways to perform deployment that rely on the
Manager web application. Apache Tomcat provides tasks for Apache Ant
build tool. Apache Tomcat Maven Plugin project provides integration
with Apache Maven. There is also a tool called the Client Deployer,
which can be used from a command line and provides additional
functionality such as compiling and validating web applications as
well as packaging web application into web application resource (WAR)
files.
Got it. The classes folder I created was "C"lasses where tomcat expects "c"lasses.
I have deployed application into GAE. When i try the url as http://aabbbaaacccc.appspot.com/_ah/remote_api. I am getting 404 Error page. I have added in web.xml file. I have given correct app id. It deploys. After deployment successful, An dialog box appears and displays file not found along with notepad.
<servlet>
<display-name>Remote API Servlet</display-name>
<servlet-name>RemoteApiServlet</servlet-name>
<servlet-class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RemoteApiServlet</servlet-name>
<url-pattern>/remote_api</url-pattern>
</servlet-mapping>
I need to deploy my app into server and start a Remote api with an other application and share the entites from an other app.
I am struggling with this issue for past 2 days. Please help me.
U can look at the error dialog box in the following link.
http://i40.tinypic.com/bfgzki.png
Thanks.
Appengine should works fine.. i've listed the all details for basic project setup. please look and find what you missed.
The Servlet Class
App Engine Java applications use the Java Servlet API to interact with the web server.
In the directory src/guestbook/, make a file named GuestbookServlet.java with the following contents:
package guestbook;
import java.io.IOException;
import javax.servlet.http.*;
public class GuestbookServlet extends HttpServlet {
#Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
}
}
The web.xml File
When the web server receives a request, it determines which servlet class to call using a configuration file known as the "web application deployment descriptor." This file is named web.xml, and resides in the war/WEB-INF/ directory in the WAR. WEB-INF/ and web.xml are part of the servlet specification.
In the directory war/WEB-INF/, a file named web.xml has the following contents:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app PUBLIC
"-//Oracle Corporation//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<servlet>
<servlet-name>guestbook</servlet-name>
<servlet-class>guestbook.GuestbookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>guestbook</servlet-name>
<url-pattern>/guestbook</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
This web.xml file declares a servlet named guestbook, and maps it to the URL path /guestbook.
The appengine-web.xml File
App Engine needs one additional configuration file to figure out how to deploy and run the application. This file is named appengine-web.xml, and resides in WEB-INF/ alongside web.xml.
In the directory war/WEB-INF/, a file named appengine-web.xml has the following contents:
<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application></application>
<version>1</version>
<threadsafe>true</threadsafe>
</appengine-web-app>
appengine-web.xml is specific to App Engine, and is not part of the servlet standard. You can find XML schema files describing the format of this file in the SDK, in the appengine-java-sdk/docs/ directory. See Configuring an App for more information about this file.
Running the Project
The App Engine SDK includes a web server application you can use to test your application.
select Debug As > Web Application.
Testing the Application
Start the server, then visit the server's URL in your browser. If you're using Eclipse and the Google Eclipse plugin, the server runs using port 8888 by default:
http://localhost:8888/guestbook
If you're using the dev_appserver command to start the server, the default port is 8080:
For details please see following tutorials:
Tutorial 1:
Tutorial 2:
Tutorial 3:
I have what I think is the simplest possible
hello world example (see below). But when asking for
"http://localhost:8080/hello" thru firefox,
it gives me the
"The requested resource (/hello/) is not available"
error.
Environment: newly installed tomcat 6.0.32 on Windows 7.
Other information:
1. None of the "similar questions" provides any clues.
From experimentation, it appears that tomcat is not
doing the mapping from localhost:8080/hello to my servlet.
I set "<load-on-startup>"
which showed me that the servlet's init entry was being
called, but doGet() is never called.
The log files show no errors.
I have tried both starting tomcat with the hello
directory already in webapps, with hello.war in
webapps, and deploying using the manager application.
All act the same way.
Some possibilities I have considered:
According to the documentation, I should
not need to use a context.xml file, and my experiments
with a context.xml produced the same resource not found
error.
localhost:8080/hello should instead be
localhost:8080/.../hello, but if so, then what is
the ... supposed to be?
Trailing / (e.g. /hello versus /hello/). I changed
the url-pattern to "/hello/*", but it fails the same
way.
I assume the problem is something simple, but I cannot
see it.
[Added 8/8/2011]
The answers about using context.xml were correct; thanks.
In looking around, it appears that an alternate way
to achieve the same effect is to put this
into my web.xml file.
<context-param>
<param-name>ContextPath</param-name>
<param-value>/dts</param-value>
</context-param>
web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>test.HelloServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
HelloServlet.java:
package test;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class HelloServlet extends HttpServlet {
public void init()
{
System.out.println("\nHelloServlet.init");
}
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
System.out.println("\nHelloServlet.doGet");
PrintWriter out = res.getWriter();
out.println("Hello, world!");
out.close();
}
}
With a Java Servlet Application (part of, but not the total sum of Java EE - Java Enterprise Edition), applications have servlets under what is called a "context path". This "context path" has to be specified in order to map any request to the application.
Apache Tomcat makes this context path pretty easy to configure, either via server.xml (not recommended) or individual context files (recommended). Both ways specify where to find your web application directory (an unpacked web application archive, or WAR file) and where to place it on the server at a context path.
As Vlad has already said, if you deploy your war file into Tomcat's webapps directory and have automatic installation on (I believe it is on by default), Tomcat will unpack the .war into a directory under that location and use the war's name as its context path. His example war file is named "helloapp.war", so, with the default settings, it would receive any request to http://localhost:8080/helloapp because its context path becomes helloapp.
Of course, once the request is sent to the context path, something needs to match against it. That's where the web.xml comes in to play. While it is possible to use the root as a matcher (every request to the context path gets handled by the same process), typically a pattern is used (such as *.do, *.action, etc), so that individual requests to the helloapp are easily distinguishable (it's easier to read and debug http://localhost:8080/helloapp/login.action and http://localhost:8080/helloapp/doSomethingElse.action than both being recognized via some parameters and the same path of http://localhost:8080/helloapp in my opinion)
So, the context path gets to your application, then your application has to do a lookup on the web.xml to see where to send the actual request. In your example, if your webapp was deployed at the context path of helloapp, to access it with the proper mapping, you would simply append /hello, so the request becomes http://localhost:8080/helloapp/hello
You are deploying your hello servlet in a webapp. Assuming the webapp is in a folder helloapp or in an archive helloapp.war in Tomcat's webapps directory then your sevlet would be accessible at http://localhost:8080/helloapp/hello
You will either need to rename the package to ROOT.war (or the ROOT directory) or modify the ROOT.xml context.xml file to point to the hello folder.
If you go to /hello/hello I bet you'll see your app. If you're using tomcat, use context.xml.
You may not need to use it for a webapp to work, but if you deploy under tomcat, things just work more coherently when you have a context.xml file.
In /yourtomcatinstall/webapps/hello/META-INF/ create a context.xml file with this information"
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/hello">
</Context>
And change the url mapping of your servlet in web.xml to / and/or /* you can have more than one url mapping for a servlet.
I'm a newb whose also been searching for a solution to the same problem. I've followed the steps that the Elite Gentleman and Bozho outlined here. So first of all, thanks a lot guys. But I still seem to have the same problem. Now as per my understanding and implementation, my situation is as follows:
My servlet class VendorRegistration is available in the folder: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\VendorReg\WEB-INF\classes
My web.xml is present at: C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\VendorReg\WEB-INF\
However, I still seem to be getting the error:
****HTTP Status 500 -
type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Wrapper cannot find servlet class VendorRegistration or a class it depends on****
I have also appended my web.xml file below for your consideration:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>VendorRegistration</servlet-name>
<servlet-class>VendorRegistration</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>VendorRegistration</servlet-name>
<url-pattern>/VendorRegistration</url-pattern>
</servlet-mapping>
</web-app>
I am trying to access the servlet through the URL: http://localhost:8080/VendorReg/VendorRegistration. What am I missing ? I had compiled the .class file sometime before I installed Apache. And hence directly copied pasted the class file in the folder. Could that be a problem ?
The servlet or one of its dependencies is missing in the classpath.
First of all, always put Java classes in a package, also servlets. Packageless classes are invisible to classes in a normal package. For servlets, this works in specific environments only. You don't want to be dependent on that.
package com.example;
public class VendorRegistration extends HttpServlet {
// ...
}
With this package, the compiled .class file must end up in /WEB-INF/classes/com/example/VendorRegistration.class. Don't forget to alter the associated <servlet-class> entry in web.xml accordingly.
<servlet>
<servlet-name>VendorRegistration</servlet-name>
<servlet-class>com.example.VendorRegistration</servlet-class>
</servlet>
If that doesn't help, then you should put the classes or JAR files containing the (in)direct classes which are specified in any of the servlet's import statements also in /WEB-INF/classes (for .class files) or /WEB-INF/lib (for JAR files). The root cause in the exception stacktrace should tell which class exactly it is. Just read the stacktrace.
See also:
Servlets info page - contains a Hello World and several useful links
From tomcat 6.0 onwards, there is change in <url-pattern>
<servlet>
<servlet-name>VendorRegistration</servlet-name>
<servlet-name>VendorRegistration</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>VendorRegistration</servlet-name>
<url-pattern>/servlets/servlet/VendorRegistration</url-pattern>
</servlet-mapping>
It worked in my case!
In my case the problem started when I made a copy/paste of HelloWorld.java class example from another project. Finally I solved it out by simply creating a new package, then a new HelloWorld.java from scratch and copy just the code for the doGet() method.
Then I restarted the server and ran http://localhost:8080/mltest/HelloWorld
And it worked!
I faced the same problem too. Actually one of my program which was working already after few changes showed me this error. I even did undo to revert the changes, still It happened to me.
Finally I found a working solution for this for my scenario.
SIMPLE:
1.Just try to clean your project and run again. If it shows the same error and if you are sure there isn't any problem with your code then,
2.Enable the "Build Automatically" menu item under "Project" menu and try to clean your project. This time it worked for me.
Heard this is because when we make some changes and run, eclipse does some changes in its background too. So even if we revert the changes, eclipse might have not reverted the changes which it did in background. So performing these 2 steps will make sure it matches with the user change with its background change.
Hope it helps and solves your problem too.
This is how I solved the problem when I had the same exception with yours.
Ensure you add the right libraries, we need to add the Library Tomcat. At the beginning, I just added the servlet-api.jar, but someone told me it's not a right way. Maybe when you implemented the project in tomcat it had some Conflicts with Tomcat.
Ensure your project in the right folder, %Tomcat_HOME%\webapps\%projectName\WEB-INF\classes\.....
Ensure web.xml in the right folder, and with right form,
%Tomcat_HOME%\webapps\%projectName\WEB-INF\web.xml
Reload the application in Tomcat.
Access the servlet through URL:
http://localhost:port/%projectName%
I'm afraid you made a mistake to try to access a servlet class directly.
Generally, the URL should be your any txt, jsp, html files under your application folder , but the servlet is used for response your "POST" or "Get" request from client side, it's immpossible to access it directly through URL.