I've got a Java EE project that works ok in Eclipse. But when I deploy it to a server with a normal Tomcat-7 it shows a 404 error on every servlet page (while .jsp works).
I've tried to deploy there a .war file and tried to just copy the whole project folder including the WEB-INF directory. The result is the same.
web.xml file contains the following:
<?xml version="1.0" encoding="ASCII"?>
<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_2_5.xsd"
version="2.5">
<display-name>acs</display-name>
<servlet>
<display-name>jsp</display-name>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>*.png</url-pattern>
<url-pattern>*.gif</url-pattern>
<url-pattern>*.jpg</url-pattern>
<url-pattern>*.css</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.svg</url-pattern>
<url-pattern>*.kml</url-pattern>
</servlet-mapping>
</web-app>
The every servlet class contains annotations like that
#WebServlet("/full")
So why it's happening? And is there a way to know where Tomcat trying to search that servlets? Or something. So now I'm like standing before the wall and it shows me 404 and I'm do not have a tiny idea what's going wrong...
For every servlet we are adding 2 main tags < servlet > and < servlet-mapping > like
<servlet>
<display-name>jsp</display-name>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
While for "default" servlet I have not found the < servlet > tag with servlet-class mapping
Related
I understand that there are a lot of similar questions, but i can't find where is my problem. So, my question is: When I had all my code in src package of my project and when I started my tomcat app all was good, but when I rewrote my app to multi module architecture I got error. Maybe I should change some paths or so on? In root target web.xml it gives me:
my web.xml: https://i.stack.imgur.com/K8wRE.png
this is error screen: https://i.stack.imgur.com/7j1Ac.png
my target/web.xml: https://i.stack.imgur.com/Oknrq.png
Building with mvn clean package is ok.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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_4_0.xsd"
version="4.0">
<display-name>MyWebApp</display-name>
<servlet>
<servlet-name>WelcomeServlet</servlet-name>
<servlet-class>servlet.WelcomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WelcomeServlet</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>CustomerServlet</servlet-name>
<servlet-class>servlet.CustomerServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>servlet.LoginServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>LogoutServlet</servlet-name>
<servlet-class>servlet.LogoutServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>servlet.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/register</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LogoutServlet</servlet-name>
<url-pattern>/logout</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>CustomerServlet</servlet-name>
<url-pattern>/customers</url-pattern>
</servlet-mapping>
</web-app> ```
Thanks for attention.
So, my solution was to change artifact. When I change the location of my tomcat webserver, I should change artifact
The Maven dependencies of IntelliJ are not up to date, see the "m"-button. This might be the cause of the problem.
Click on the "m"-button with "turning arrows" in the top right corner of your editor window.
mvn and IntelliJ manage dependencies independently.
I am developing a website and i am finding hosting issues. I have put all my .jsp files in the root directory.
I am able to see the JSPs (accessing directly to them).
But, when i try to perform the same check the WEB-INF/classes, I get the error:
Not Found The requested URL /AC/SearchController was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
This is my Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>AC</display-name>
<welcome-file-list>
<welcome-file>Home.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>AdvisorProfileServlet</servlet-name>
<servlet-class>org.AC.controller.AdvisorProfileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdvisorProfileServlet</servlet-name>
<url-pattern>/AC/AdvisorProfilePage?aId=*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ForgotPasswordRedirectController</servlet-name>
<servlet-class>org.AC.controller.ForgotPasswordURLController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ForgotPasswordRedirectController</servlet-name>
<url-pattern>/ForgotPasswordAdvisor</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AdvisorMyAccountRequest</servlet-name>
<servlet-class>org.AC.controller.AdvisorMyAccountRequestController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdvisorMyAccountRequest</servlet-name>
<url-pattern>/AC/requests.jsp</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ForgotPasswordRedirectControllerUser</servlet-name>
<servlet-class>org.AC.controller.UserForgotPasswordURLController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ForgotPasswordRedirectControllerUser</servlet-name>
<url-pattern>/ForgotPasswordUser</url-pattern>
</servlet-mapping>
</web-app>
This might also be a server config, because I created the project on Tomcat server 8, but I guess the server which is now hosting it is Tomcat 7.
How can I resolve this?
Please declare "/AC/SearchController" as url pattern in your web.xml
I have a running war servlet in tomcat6. It works fine in tomcat. Now I need to migrate it to glassfish and it doesn't work.
First it show a big amount of problems (context, path null, etc) So I decided to create a new project in eclipse and copy all my classes in java and libraries to the new one.
Now I have a problem because I can upload the new .war to glassfish but servlet doesn't answer to my queries.
I think I have a problem with my glassfish-web.xml and almost sure with other things which I don't know.
The autogenerated glassfish-web.xml is this one:
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
<context-root>/TEST</context-root>
</glassfish-web-app>
And the path to one of my resources is this one: /students (class path) /listNames (method resource inside class)
So I guess I should use this url to access to my resource: localhost:port/nameOfMyWar/TEST/students/listNames
But it shows a white screen in my browser and log doesn't show anything.
What do I have to modify from a tomcat servlet project to adapt to a glassfish project? Is there a guide or some webpage with clues?
This is my actual web.xml:
<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>SERVLET</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>/axis2-web/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.my.example.servlet</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
<servlet>
<display-name>Apache-Axis Servlet</display-name>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<servlet>
<display-name>Apache-Axis Admin Servlet Web Admin</display-name>
<servlet-name>AxisAdminServlet</servlet-name>
<servlet-class>org.apache.axis2.webapp.AxisAdminServlet</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisAdminServlet</servlet-name>
<url-pattern>/axis2-admin/*</url-pattern>
</servlet-mapping>
</web-app>
I have tried to find a solution searching on Google, but did not succeed.
This is the structure of my application's folder.
<PROJECT_NAME>
--->WebContent
--->index.html
--->WEB-INF
--->META-INF
I deployed my application in Tomcat server.
My web.xml config file is the following:
<?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" id="WebApp_ID" version="3.0">
<display-name>fp</display-name>
<servlet>
<servlet-name>FpServlet</servlet-name>
<servlet-class>com.fp.FpServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>FpServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I try to access localhost:8080/project_name/,and everything works fine, but when I try to access the index.html file like this localhost:8080/project_name/index.html, it doesn't show the index.html content. It shows my root project content. (localhost:8080/project_name/)
How can I get the index file content posted in the browser?
Any help will be very appreciated.
Please note that the folder is named "WEB-INF", not "WEB.INF".
You can use default servlet to serve your static resources. Here is how this can be used with tomcat:
<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>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
I want to map my RPC service to http://path.com/RPC2 rather than /RPC2/
Inside my web.xml file, I currently have the url-pattern set to /
<servlet-mapping>
<servlet-name>RPC2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I tried to merely remove the url-pattern, but this didn't work. When I remove the url-pattern entry, Tomcat won't deploy it and Jetty works but at ../RPC2/
Here's the full XML file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
<servlet>
<description>Automatos RPC Server</description>
<servlet-name>RPC2</servlet-name>
<servlet-class>RPCServlet</servlet-class>
<init-param>
<param-name>streamMessages</param-name>
<param-value>1</param-value>
</init-param>
<init-param>
<!-- Optional! Defaults to text/xml and ISO-8859-1 -->
<param-name>contentType</param-name>
<param-value>text/xml; charset=ISO-8859-1</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RPC2</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
Deploy your webapp on context root (in Tomcat, just rename the WAR to ROOT.war or set <Context path=""> instead of <Context path="/RPC2">). This way your webapp will be deployed to http://path.com. This way you can map the servlet on an URL pattern of /RPC2 and the servletcontainer won't auto-redirect to the webapp root / anymore.