GWT RPC call don't seems to work when i deploy my war file to TOMCAT (tomcat/webapps/ROOT/war).
It gives me an error:
The requested resource
(/war/myproject/call) is not
available.
If i change the directory structure and then deploy directly war contents (not war directory itself), like (tomcat/webapps/ROOT/project.html, project.css, project, etc...) then it works.
Can someone please explain me whats going on?
I think there might a problem at:
<servlet>
<servlet-name>callServlet</servlet-name>
<servlet-class>com.myproject.server.dao.Call</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>callServlet</servlet-name>
<url-pattern>/myproject/call</url-pattern>
</servlet-mapping>
The thing is that a single Tomcat server can have multiple applications deployed, each in its so-called context. The applications are deployed in the webapps folder and each folder is mapped to one context, while the ROOT folder is the default (no-context).
To access an application on Tomcat, you specify the context after the URL. For example if you had an application (context) Test in webapps/Test folder, you would access it like this:
http://localhost:8080/Test
But applications in the ROOT folder have no context and are accessed by simply going to localhost:8080. And this is your case. Tomcat is looking for you application directly in the ROOT folder but you have your app in the ROOT/war folder. In other words, the RPC call expects the myproject folder to be under the ROOT folder and not under the ROOT/war folder. That's why it's not working.
If you still wanted to have your war folder within the ROOT folder, you would have to change the url-pattern to /war/myProject/call.
Well i found the solution, it had to do with Tomcat's way of operation.
Open your project war directory
Select all the files (html/jsp , images, WEB-INF etc...)
Compress all the files into a single project.zip archieve
Rename the project.zip into project.war
Copy project.war into Tomcat/webapps/
Restart Tomcat server
You will now notice inside webapps directory that project.war has been decompressed into a project directory, if you open it you will find all the .war contents(html/jsp, images, WEB-INF, etc...)
Access it from here http://localhost/project or http://localhost/project/index.html or index.jsp.
The error was: I was compressing only the war directory (not it's inside contents) into project.war.
look like, servlet is not initializing for you war try to change SERVLET tag as
i.e. add tag
<load-on-startup>1</load-on-startup>
this tag ensures that servlet should be loaded
<servlet>
<servlet-name>callServlet</servlet-name>
<servlet-class>com.myproject.server.dao.Call</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
hopefully this will work
Related
I have an existing jetty application that i need to modify. Basically i just need one access point that can handle POST requests. I have access to the WEB-INF directory of the project. There i have web.xml file and a lib folder. As i understand from jetty documentation jars under lib will be loaded automatically. Is it possible to add a custom jar under lib folder and the somehow configure web.xml so that my jar will handle HTTP requests from a certain URL? If so how would i start with that?
You can simply create a jar with your Servlet class inside (a class that extends HttpServlet) and add the servlet declaration inside the web.xml
<servlet>
<servlet-name>A_Name</servlet-name>
<servlet-class>your.new.ServletClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>A_Name</servlet-name>
<url-pattern>/the/path/you/want</url-pattern>
</servlet-mapping>
Individually, each WAR file works fine. However, when I deploy both WAR files in the webApps folder, I get the "crossdomain pre-flight No Access-Control-Allow-Origin" error.
The key here is that the FIRST war file I access through a web request works fine. The second one always fails with this error. So, with a fresh server restart, WAR file A is accessed first, and it works while WAR file B fails. Conversely, if I restart the server and WAR file B is accessed first, it works while WAR file A fails.
The COORS headers which allow cross domain web access are located in the web.xml files of each war application.
Thanks in advance for your help! I am really struggling here.
Ryan
I fixed it by adding the following to the web.xml of both WAR files:
<context-param>
<param-name>log4jExposeWebAppRoot</param-name>
<param-value>false</param-value>
</context-param>
I have an mp4 video on my GlassFish java application server. What URL do I use to access it in a browser?
The video path in the application on the server is:
myapp/WEB-INF/videos/myvideo.mp4
I tried adding this to my web.xml file:
<servlet>
<servlet-name>myvideo</servlet-name>
<servlet-class>videos.myvideo.mp4</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myvideo</servlet-name>
<url-pattern>/myvideo</url-pattern>
</servlet-mapping>
and restart the server, then go to the URL: https://www.example.com/myapp/myvideo but that just gave this error:
java.lang.ClassNotFoundException: videos.myvideo.mp4
Obviously it's not a servlet, but not sure what else to try.
Why are you trying to access the video as a servlet and not as a static asset, like you would an image? Using a servlet mapping is obviously wrong.
Instead if you have a running WebApp in GlassFish you should be able to access it via https://www.example.com/myapp/videos/myvideo.mp4 assuming you've put the videos folder under your webapp's j2ee root.
The j2ee root would be configured in your application.xml as the web-uri. In your case it is likely that the myapp folder is your j2ee root. So move your videos up a folder.
(Converted comment 'discussion' into an answer).
My WebApp uses Java annotations to map the URL to the servlet (#WebServlet) and I don't have a web.xml file. I want to foward the request to another HTML file and I did it like so:
request.getRequestDispatcher("/WEB-INF/test/testpage.html").forward(request, response);
It works, but I can't get additional resources (javascript) from the server.
<script type="text/javascript" src="testsuite.js"></script>
testsuite.js is located in /WEB-INF/test/testsuite.js, the same folder as testpage.html. When requesting testsuite.js I get 404. How can I configure Tomcat to serve all the resources in my work tree without a web.xml? Worst case I will simply embed JS.
Additionally I let eclipse install the web server on my local machine so I have no idea how they are deployed.
You have to move resources outside of your WEB-INF folder. It is a special folder for compiled Java code, jars, configuration files etc.
The WEB-INF folder is restricted in application servers and servlet containers for security reasons, so for example a request for /appname/WEB-INF/web.xml will be deined of course.
Static resources such as *.html files, *.css files, *.js files, images etc. should be placed outside of WEB-INF folder, in your case the test folder should be moved up next to WEB-INF.
This is my first attempt at making a Servlet Program which just displays text/html. I created the directories as is should be -
C:\Java_Advanced\DemoServlet
DemoServlet (folder)
--WEB-INF
----classes (containing my .class file)
----lib
----web.xml
--MyServlet.java (sitting in parallel with WEB-INF)
I'm using tomcat apache 8.0.9
Here is my web.xml -
<web-app>
<servlet>
<servlet-name>Hi</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hi</servlet-name>
<url-pattern>/run</url-pattern>
</servlet-mapping>
</web-app>
I made the war file (demo.war) of whatever was inside the DemoServlet.
I started the Tomcat Apache service. I have given a port number other than the default 8080. I deployed my demo.war successfully (I am assuming because the message OK was printed above AND the application /demo's Running is coming to be true(I am told that a true state means there is no problem with the xml file)).
But still I open the new tab/window of the browser and type "localhost:myportnumber/demo/run" and all I get is HTTP Status Error 404 description: The requested resource is not available. I have tried refreshing with ctrl+F5, tried different browsers but still gives the same error.
What is wrong here? I searched over the internet and found something on this site:
http://www.ntu.edu.sg/home/ehchua/programming/howto/Tomcat_HowTo.html#TomcatDebug
(Scroll all the way to the bottom where it says for error 404)
Everything is fine until 3.d point. The sub-directory mentioned as xxxx is "demo" in my case right? It does exist. And so does demo.war alongside it in parallel(is that how it should be?)
C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\demo
C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\demo.war
When I open the demo directory I DO NOT get a WEB-INF sub-directory. Instead there is a META-INF sub-directory and alongside it MyServlet.java file. Opening the META-INF folder there is a MANIFEST.MF file. Now what is that?? So, is this the reason for getting 404. Even if it is how do I fix it?
It looks as if the structor of your war file is wrong.
The inside of the war file should at least look like:
WEB-INF/web.xml
WEB-INF/classes/MyServlet.class
Look in your war file. It is just a zip file.
I'd strongly suggest using correct tool for building Java EE applications. You can use Eclipse with WTP. It will create correct project structure, allow you to more easily create and validate descriptors and you will be able to deploy your applications directly to server from the tool.
There must be a problem with current structure of your war file (its hard to tell from your description what is file/folder nesting) or building war itself.