I am using tomcat7 and have a small Java application that needs to be deployed under ROOT. The reason for this has to do with the client's inability to specify the webapp's proper context path at this time.
I have an index.html in this webapp and my issue is that when I deploy the application under the webapp name - ${catalina_home}/mywebapp - the index.html renders without a problem when I navigate to http://localhost:8080/mywebapp.
However, when I deploy it under ROOT - ${catalina_home}/ROOT - the index.html inside does not render when I navigate to http://localhost:8080/. The error is 404 not found. Does this have anything to do with overriding tomcat's default page?
My web.xml:
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/</param-value>
</context-param>
...
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
...
Can someone explain why this is so?
Thanks in advance.
UPDATE: I see in this stackoverflow Display html page in tomcat from maven RESTEasy webapp that the issue may be that my filter says anything under /* should go to the servlet. I tried to set up a default servlet for .html pages, but that does not see to help yet...
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
How do you deploy the app as ROOT? If you package as war file, to deploy as ROOT, change the war file to ROOT.war and have the index.html under the ROOT folder. Also check the web.xml under WEB-INF to have the welcom page set to index.html as below:
<welcome-file-list>
<welcome-file>
index.html
</welcome-file>
</welcome-file-list>
I found the answer here - http://docs.jboss.org/resteasy/docs/3.0.2.Final/userguide/html_single/:
"The downside of running Resteasy as a Servlet is that you cannot have static resources like .html and .jpeg files in the same path as your JAX-RS services. Resteasy allows you to run as a Filter instead. If a JAX-RS resource is not found under the URL requested, Resteasy will delegate back to the base servlet container to resolve URLs."
I created a filter instead and I was able to serve both the static page and my regular REST resources.
Related
I want to run my first web application and I am getting this error
I have searched the web but I cant figure out what the problem is.
I have trying googling what nesting is but I could not understand what it is talking about
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/todo-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/todo-servlet.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:342)
web.xml
The path to the todo-servlet is configured here.
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/spring-mvc/*</url-pattern>
</servlet-mapping>
I have created todo-servlet.xml in src/main/webapp/WEB-INF/todo-servlet.xml
but I am still getting file not found exception
Refer below link and follow step by step check configuration in xml as well as in class and file path locations.
http://websystique.com/springmvc/spring-4-mvc-helloworld-tutorial-full-example/
This usually happens in a Spring Web application, when a DispatcherServlet is set up in the web.xml for Spring MVC. By default, Spring will look for a file called exactly springMvcServlet-servlet.xml in the /WEB-INF directory of the web application.mvc-servlet.xml file that indeed exists under /WEB-INF.
or it may happen because when something in the application points to an XML resource that doesn't exist, or is not placed where it should be.
Create the file and to place it under the /src/main/resources directory of the project – this way, the file will exist on the classpath.
tried adding servlet mapping in web.xml as shown below but unable to load the page.
Here is the directory structure for webapp|->html|->hello.jsp or hello.html (tried with both jsp and html)
Click here to see directory structure
web.xml file
<servlet>
<servlet-name>hello</servlet-name>
<jsp-file>/html/hello.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
tried with multiple path in jsp-file tag for example /webapp/html/hello.jsp but end up with ERROR: javax.servlet.ServletException: missing jspFile:
This error at least tells servlet dispatcher is able to get the request /hello . but further its failing to load JSP or HTML page.
I'm trying to get this tutorial to work
https://avaldes.com/file-upload-example-using-restful-web-service-with-jax-rs-and-jersey/comment-page-1/#comment-319
This looks like an eclipse project. I downloaded it and imported it into eclipse. How to run it? There was no "run on server" or "run as web page". The only options available was "run as application" and "run as applet", neither of which this is. My project tree looks just like theirs except for JRE System Library, Pivotal tc Server, and Web App Libraries. I gave up.
Next I went to NetBeans and imported the eclipse project. Clicked green Run button and up popped the web page, running on tomcat. But the url showed http://localhost:8084/, not localhost:8084/RestfulFileUploadExample.
I clicked the Browse... button and grabbed a file. Then clicked Upload File button. It put the following url into the browser: http://localhost:8084/RestfulFileUploadExample/rest/files/upload but got "The requested resource is not available. Now what?
there are issue in web.xml file check this file again it should be on WEB-INF folder and then check mapping of class file is proper or not. you can use this bellow code :-
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:Beans.xml</param-value>
</context-param>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.demo.services</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
I got a servlet, which I'm trying to get to through a hyperlink.
I checked the Servlet's folder availability by a hyperlink to JSP file on that folder.
I also checked the Servlet itself when asking it on the hyperlink with the .java extension, and I got
the code of that Servlet on the browser.
When I'm trying to connect to that Servlet either to doGet or doPost, I'm getting a 404 HTTP error,
the resource is not available.
Web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>controllers.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/controllers</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/views/welcomePage.jsp</welcome-file>
</welcome-file-list>
</web-app>
What is wrong?
As you post in your question
I also checked the Servlet itself when asking it on the hyperlink with the .java extension
I think you are putting the servlet class file in a folder under your web folder and that is why you can access trough the url.
project
src
web
controllers
TestServlet.java
page.jsp
WEB-INF
classes
As opposed of the jsp files the servlet classes must be in the WEB-INF/classes folder (the .class file not the .java file), and the source code of your class must be in the src folder of your project under the package controllers so:
project
src
controllers
TestServlet.java
web
page.jsp
WEB-INF
classes
controllers
TestServlet.class
If you're using eclipse, netbeans or other IDE when you put your java class in the source folder it automatically put the .class in the WEB-INF/classes folder.
You map your servlet to the URL pattern /controllers - so your post should go to http://localhostOrWhatever/maybeYourWebAppDirectoryDependingOnSetup/controllers
I m trying to debug some jsp pages in eclipse. These pages depends on some other projects, that are located in workspace. The physical files are located in webapps directory. I'm using tomcat7 as server. I have started Tomcat with standard configuration(debug at port 8000) and left also port 8000 in remote debug configuration. In my workspace there is a ic-config with WEB-INF and web.xml. It maps com.quartal.irtoolbox.ic.ControllerServlet to Controller like the following:
<servlet>
<servlet-name>Controller</servlet-name>
<servlet-class>com.quartal.irtoolbox.ic.ControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/Controller</url-pattern>
</servlet-mapping>
But when i try to access Controller , it is not accessible at all.I'm getting the error: "The requested resource (/Controller) is not available". What should i change and how should i call the servlet to be able to get and debug it?
Thanks
Magda