I have deployed a sample spring java application to weblogic server (11g, 10.3.6). I have index.html at the root and I set that as the welcome-file in web.xml. But when I try to access the application, I am getting 'Error 404 -- Not Found'. Also, I noticed same issue with js and css files.
index.jsp works fine at the same location.
Here is my web.xml.
<display-name>hello</display-name>
<welcome-file-list>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
The reason for this is the root level mapping(/) for your Spring DispatcherServlet. All the requests are forward to Spring servlet:
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I workaround this situation by using *.do for my Spring controllers and update the servlet mapping as mentioned here:
<servlet-mapping>
<servlet-name>appServlet/servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
But this will require you to update the 'calls to your Spring controller' with a .do at the end of the URLs.
Related
I am trying to use Jersey 2.x and have a servlet call "myapp", configuration on web.xml is as follows:
<servlet>
<servlet-name>myapp</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>
com.private.myapp.resource
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
and have a servlet mapping as follows
<servlet-mapping>
<servlet-name>myapp</servlet-name>
<url-pattern>/instance/create</url-pattern>
<url-pattern>/instance/list</url-pattern>
</servlet-mapping>
when I request to $SERVER_ROOT/instance/create or $SERVER_ROOT/instance/list its return 404
but when I change servlet mapping as follows
<servlet-mapping>
<servlet-name>myapp</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
then requesting to $SERVER_ROOT/instance/create or $SERVER_ROOT/instance/list response as expected
can anyone tell what I am missing?
My project Spring MVC. and i am novice.
I had a problem I could not run my project with HTML file. I had error 404 but there wasn't with jsp.
I solved the problem with help second solution by link:
How to map requests to HTML file in Spring MVC?
So, i have the DispatcherServlet and the JspServlet in web.xml.
I uderstand the JspServlet handling my HTMl reqest and the DispatcherServlet handling all other.
My question:
Is it normal that i have these two servlets, or I can make so that the DispatcherServlet handling and HTML and all the other?
my web.xml:
<display-name>FirstSpringMVC</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>htmlServlet</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>htmlServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
Usually, these two requests:
localhost:8080/test
localhost:8080/test/
have no difference.
However, when I add a servlet-mapping config:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
then
localhost:8080/test/
Does not work, it would return 404 error, I don't understand that I had added a config like this:
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/rest-servlet.xml,
/WEB-INF/interceptor-servlet.xml,
/WEB-INF/controller-servlet.xml,
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
So, why would the request not go to this servlet, what is the magic in *.html? The others like *.txt, *.jpeg would not cause this problem.
remove
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
leave
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
and let Spring distinguish between rest and html requests.
i am trying to deploy my app to GAE but i allways get 404 not found error on all pages(jsp) except for default. RESTful webservices working without problem. I am using netbeans 7.1.1 and gae 1.6.4.1
When I test it locally, everything works fine without any problem. But when I upload it do gae, allways only default page is available. I tryied almost everything.
I tryied to check whether the files are on GAE using appcfg.cmd. I downloaded my files from GAE and found out that noone is missing so the update process was probably successful.
I tryied to upload it with appcfg script instead of netbeans plugin but the process failed because of:
com.google.appengine.tools.admin.JspCompilationException: Failed to compile jsp files.
I cant simply make it working using appcfg script, searech internet for almost whole day and found no possible solution. Uploading with netbeans plugin worked without problem.
So what can be the reason to allways throw 404 on gae? Please help.
Thx very much. If you need any other info, i will be glad to post it here.
Ok,Here is my web.xml
<web-app version="2.5" 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">
<servlet>
<servlet-name>facebookLogin</servlet-name>
<servlet-class>Login.FacebookLogin</servlet-class>
</servlet>
<servlet>
<servlet-name>PlanProcess</servlet-name>
<servlet-class>Input.PlanProcess</servlet-class>
</servlet>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>facebookLogin</servlet-name>
<url-pattern>/facebooklogin</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>private</servlet-name>
<jsp-file>private.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>private</servlet-name>
<url-pattern>/private</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>editPlan</servlet-name>
<jsp-file>editTrainingPlan.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>editPlan</servlet-name>
<url-pattern>/private/trainingplan/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>listplans</servlet-name>
<jsp-file>listTrainingPlans.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>listplans</servlet-name>
<url-pattern>/private/listplans</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>visualize</servlet-name>
<jsp-file>visualize.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>visualize</servlet-name>
<url-pattern>/private/visualize</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>graph</servlet-name>
<jsp-file>graph.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>graph</servlet-name>
<url-pattern>/graph/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>created</servlet-name>
<jsp-file>created.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>created</servlet-name>
<url-pattern>/created</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>login</servlet-name>
<jsp-file>login.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>newRecord</servlet-name>
<jsp-file>newRecord.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>newRecord</servlet-name>
<url-pattern>/private/newrecord</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>newPlan</servlet-name>
<jsp-file>newPlan.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>newPlan</servlet-name>
<url-pattern>/private/newplan</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>newExcercise</servlet-name>
<jsp-file>newExcercise.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>newExcercise</servlet-name>
<url-pattern>/private/newexcercise</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>Webservice</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>test.InsertToDb</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/testinsert</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>recordProcess</servlet-name>
<servlet-class>Input.RecordProcess</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>recordProcess</servlet-name>
<url-pattern>/record_process</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>excerciseProcess</servlet-name>
<servlet-class>Input.ExcerciseProcess</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>excerciseProcess</servlet-name>
<url-pattern>/excercise_process</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>PlanProcess</servlet-name>
<url-pattern>/plan_process</url-pattern>
</servlet-mapping>
After hours of debugging and searching, i found out, that if you want to map jsp files
you have to use
<servlet>
<servlet-name>editPlan</servlet-name>
<jsp-file>**/**xxx.jsp</jsp-file>
</servlet>
instead of
<servlet>
<servlet-name>editPlan</servlet-name>
<jsp-file>xxx.jsp</jsp-file>
</servlet>
The '/' in path is essential, it will work on loaclhost but not deployed on gae. What a crap...
I never mapped JSPs to anything in web.xml. Why do you do that?
I have Vaadin web application with spring security integration for authentication. The configuration of the Vaadin servlet is pretty simple:
<servlet>
<servlet-name>Vaadin Application Servlet</servlet-name>
<servlet-class>com.example.SpringApplicationServlet</servlet-class>
<init-param>
<param-name>applicationBean</param-name>
<param-value>mainApplication</param-value>
</init-param>
<init-param>
<param-name>widgetset</param-name>
<param-value>com.example.widgetset.CustomWidgetSet</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Vaadin Application Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
The servlet initializes the Spring Context and returns the Vaadin application. I have also configured the security for that and have a custom login form configured like this:
<servlet>
<servlet-name>login</servlet-name>
<jsp-file>/jsp/login.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>login_error</servlet-name>
<jsp-file>/jsp/loginError.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>login_error</servlet-name>
<url-pattern>/login_error</url-pattern>
</servlet-mapping>
The login form is styled with an external css and there are also some images. Basically the images are located in /jsp/img and the stylesheet in /jsp/login.css. So the WAR structure looks like:
/jsp
/META-INF
/VAADIN
/WEB-INF
Neither the images nor the css gets loaded, because obviously all those requests are mapped to the vaadin servlet. How can I define some static resources directory, which wouldn't be served by the Vaadin servlet? I have tried the spring mvc:resources but that didn't work. Thank you for your help.
Bye,
Filip
I have figured this out. Although it is rather a workaround. I have mapped the Vaadin Application Servlet to something like /app/* instead of to /* (Remember that in this case you also have to map the same servlet to /VAADIN/*). With this configuration I am able to access the jsp directory from my webapp and everything works fine. I have deleted the whole Spring Resources configuration, as this just didn't work.
So once more, I am still pretty not pretty comfortable with this solution and would rather have my RESOURCES dir configured other way, but the client is happy :). If anyone has got the right solution I would appreciate to read it.
Use a url rewrite filter to get more contro on url mapping.
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
then map Vaadin application to /vaadin for example and configure url maping in urlrewrite.xml
<rule>
<from>/styles/**</from>
<to last="true">/styles/$1</to>
</rule>
<rule>
<from>/images/**</from>
<to last="true">/images/$1</to>
</rule>
<rule>
<from>/**</from>
<to>/vaadin/$1</to>
</rule>
<outbound-rule>
<from>/vaadin/**</from>
<to>/$1</to>
</outbound-rule>
EDIT
Other option is put static files in /VAADIN/ directory.
I have figured this out. Although it is rather a workaround. I have mapped the Vaadin Application Servlet to something like /app/* instead of to /* (Remember that in this case you also have to map the same servlet to /VAADIN/*). With this configuration I am able to access the jsp directory from my webapp and everything works fine. I have deleted the whole Spring Resources configuration, as this just didn't work.
So once more, I am still pretty not pretty comfortable with this solution and would rather have my RESOURCES dir configured other way, but the c
Might be late but for who is still having problems with serving static content while using vaadin /* mapping, the solution I found was using apache's default servlet org.apache.catalina.servlets.DefaultServlet, so a web.xml will have something like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/j2ee"
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>
<servlet-name>myservlet</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<param-name>UI</param-name>
<param-value>com.ex.myprj.MyUI</param-value>
</init-param>
<!-- If not using the default widget set-->
<init-param>
<param-name>widgetset</param-name>
<param-value>com.ex.myprj.AppWidgetSet</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Static content Servlet</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Static content Servlet</servlet-name>
<url-pattern>/customer/*</url-pattern>
</servlet-mapping>
</web-app>
So in the example above, despite having vaadin at /*, the /customer/* part will be served as static content by the DefaultServlet