No mapping found for resource files in DispatcherServlet - html

I've got the following problem on every single page I am trying to access
WARNING [http-nio-8080-exec-7]
org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping
found for HTTP request with URI
[/cart/%3Cc:url%20value='/resources/css/bootstrap.css'%20/%3E] in
DispatcherServlet with name 'springmvc-dispatcher
There are warnings, but those resources are visible (both css and scripts are working, still gives errors), and I have nothing underlined in jsp files.
<link href="<c:url value='/resources/css/bootstrap.css' />" rel="stylesheet"/>
<script src="<c:url value="/resources/js/controllers.js"/>"></script>
I have above paths to css and js in every jsp file.
Project-Structure
And my filter mapping:
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

You haven't used DispatcherServlet in your mapping. Just try this.
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>

Related

Custom error pages not showing up?

I have Tomcat installed and whenever the user hits a 404 pages or 500 page it shows the Tomcats error page. But, then I have created a custom 404 and 500 error pages and put it inside my web.xml file. But, I can't see my custom error page displayed. Please check my code and see what is going on. Thank you for the help.
Here is my code:
<?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">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>report.url</param-name>
<param-value>https://MY_URL_LINK.net/jasperserver-pro/rest_v5/reports/organizations/organization_2</param-value>
</context-param>
<context-param>
<param-name>report.path.mode</param-name>
<param-value>report.path</param-value>
</context-param>
<context-param>
<param-name>report.path.test</param-name>
<param-value>C:\\Program Files\\glassfish-4.1\\glassfish\\domains\\domain1\\applications\\PayApp-5.0-SNAPSHOT\\reports\\</param-value>
</context-param>
<context-param>
<param-name>report.path</param-name>
<param-value>/usr/share/glassfish3/glassfish/domains/domain1/applications/PayApp/reports/</param-value>
</context-param>
<!-- THIS IS MY ERROR PAGES SHOWN BELOW -->
<error-page>
<!-- Missing resource -->
<error-code>404</error-code>
<location>/Error404.xhtml</location>
</error-page>
<error-page>
<!-- Uncaught exception -->
<error-code>500</error-code>
<location>/Error500.xhtml</location>
</error-page>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
25
</session-timeout>
</session-config>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>org.pay.filters.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/secure/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<resource-ref>
<res-ref-name>/oracleInstance</res-ref-name>
<res-type>javax.sql.ConnectionPoolDataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>jdbc/w2Instance</res-ref-name>
<res-type>javax.sql.ConnectionPoolDataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>

Unable to download file using CORS

I want to make a Cross-Domain request to download a file from my java web application. I am using the CORS filter and have included the configuration in my deployment descriptor(web.xml):
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
I have the cross domain URL in the href attribute:
download
Now when I click the link, the whole page is redirected and the file is downloaded. Can I know what how can I achive this.
Thanks
I faced a similar problem sometime ago. You will not be able to download the file using a GET request using href attribute as u mentioned in the question.
Instead you can submit a form embedded in an iframe as suggested here and submit the form with your file id as a hidden element and it should trigger the download. So your anchor tag shall be:
download
Now pass your fileId as parameter to the onclick JS function and define it like this:
function downloadFile(fileId) {
let $iframe, iframeDoc, iframeHtml;
if(($iframe = $('#download_frame')).length === 0) {
$iframe = $('<iframe id="download_frame" +
' style="display: none;" src="about:blank"></iframe>'
).appendTo('body');
}
iframeDoc= $iframe[0].contentWindow;
if (iframeDoc.document) {
iframeDoc= iframeDoc.document;
}
iframeHtml= '<html><head></head><body><form method="POST" action="http:localhost:8080/MyProject/downloadAction.action"><input type="hidden" name="fileId" value="'+fileId+'"></form></body></html>';
iframeDoc.open();
iframeDoc.write(iframeHtml);
$(iframeDoc).find('form').submit();
}
You can follow similar approach for single or multiple files.
Also to add you can include this in ur web.xml in the filter configuration:
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,X-Test-Header,Cache-Control
</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials
</param-value>
</init-param>

Link to primefaces theme stylesheet is missing session id

I've added a primefaces theme to the web.xml...
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>le-frog</param-value>
</context-param>
... and get a link to the stylesheet in the head ...
<link type="text/css" rel="stylesheet" href="/pos2hue/javax.faces.resource/theme.css.jsf?ln=primefaces-le-frog" />
...which would be correct, if we wouldn't use single-sign-on, which redirects all URLs without a sessionid to the login screen. So the stylesheet resolves to:
<HTML><HEAD><TITLE>HTTP Post Binding (Request)</TITLE></HEAD><BODY Onload="document.forms[0].submit()"><FORM METHOD="POST" ACTION="https://configured.identity.url"><INPUT TYPE="HIDDEN" NAME="SAMLRequest" VALUE="..."/></FORM></BODY></HTML>
Other links coming from primefaces are OK, for example:
<script type="text/javascript" src="/contextroot/javax.faces.resource/jsf.js.jsf;jsessionid=eo0Oo0oK37AUm7bNOaFqdrB-?ln=javax.faces"></script>
As additional info I have to add:
session mode in web.xml is set to "URL" (i don't want to change that)
<session-config>
<tracking-mode>URL</tracking-mode>
</session-config>
for single-sign-on we use picketlink (i have a picketlink.xml in the WEB-INF folder)
web server is JBoss EAP 6.1
Any ideas, how i could
make primefaces add the sessionid to the stylesheet href?
make an exclusion to the single-sign-on mechanism?
or make it work otherwise?
Adding the stylesheet directly is possible, but unwanted, because we use a JSF2 template for all applications, but i want to configure it for one application only.
Thank you in advance!

using HttpServlet to generate html-img source image -> how to request via POST?

I use a HttpServlet to generate an html image dependent on multiple IDs like this:
<img src="./someServlet?ids=123,124,125,126[...]" alt=""/>
someServlet extends from javax.servlet.http.HttpServlet overwriting the doGet()and doPost() methods. It sets the response contenttype to img/png and uses the response outputstream to commit the generated image to the view.
The servlet mapping is done in web.xml:
<servlet>
<servlet-name>SomeServlet</servlet-name>
<servlet-class>my.package.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SomeServlet</servlet-name>
<url-pattern>/someServlet</url-pattern>
</servlet-mapping>
My question: How do I send the request above via POST instead of GET? I tried surrounding it by the <form> tag setting the method to POST, but as expected, it didn't work.
EDIT: I need this because my request (with 5-10 UUIDS) exceeds the limit of a GET request
You cannot change an <img> element to send a POST request instead of GET. This makes no sense.
As per the comment on the question the query string length limit seems to be the main reason:
I want to use POST, because the get parameter length is limited. I commit 5-10 UUIds as a parameter, which exceeds the length of a GET request.
Just pass it as part of URL instead, as path info. So, instead of
<img src="someServlet?id1=123&id2=234&id3=345&id4=456&id5=567" alt=""/>
use
<img src="someServlet/123/234/345/456/567" alt=""/>
You only need to change your servlet's URL pattern to
<url-pattern>/someServlet/*</url-pattern>
and change the way to obtain the IDs as follows
String[] ids = request.getPathInfo().substring(1).split("/");
// ...

Faces Servlet threw exception java.lang.StackOverflowError

Ok, I've run across my first StackOverflowError since joining this site, I figured this is a must post :-). My environment is Seam 2.0.1.GA, JBoss 4.2.2.GA and I'm using JSF. I am in the process of converting from a facelets view to JSP to take advantage of some existing JSP tags used on our existing site. I changed the faces-config.xml and the web.xml configuration files and started to receive the following error when trying to render a jsp page. Anyone have any thoughts?
2008-09-17 09:45:17,537 DEBUG
[org.jboss.seam.contexts.FacesLifecycle]
Begin JSF request for /form_home.jsp
2008-09-17 09:45:17,587 ERROR
[org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/].[Faces
Servlet]] Servlet.service() for
servlet Faces Servlet threw exception
java.lang.StackOverflowError
at org.apache.catalina.core.ApplicationHttpRequest.getAttribute(ApplicationHttpRequest.java:210)
at org.apache.catalina.core.ApplicationHttpRequest.getAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.getAttribute(ApplicationHttpRequest.java:222)
at org.apache.catalina.core.ApplicationHttpRequest.getAttribute(ApplicationHttpRequest.java:222)
...
My faces-config.xml file is now empty with no FaceletsViewHandler:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
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-facesconfig_1_2.xsd">
</faces-config>
And my Web.xml file:
<?xml version="1.0"?>
<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">
<!-- Ajax4jsf -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Seam -->
<listener>
<listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Seam Resource Servlet</servlet-name>
<servlet-class>org.jboss.seam.servlet.SeamResourceServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Seam Resource Servlet</servlet-name>
<url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>
<!-- Seam end -->
<!-- JSF -->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jsp</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
I was able to figure out this problem. Apparently you can not configure web.xml to have the same param-value of .jsp for Javax.faces.DEFAULT_SUFFIX as the Faces Servlet url-pattern (*.jsp). If you change your url-pattern to .jspx or to /whateverdirnameyouwant/ the application starts up with no stack overflow errors. (note: the key is that DEFAULT_SUFFIX and Faces Servlet url-pattern cannot be the same regardless of what they are.) Hope this helps anyone else that experiences this specific problem.
Stack overflows in java are almost always caused by infinite recursion / method calls. In your case given the stack trace, it appears 'getAttribute()' is being called repeatedly until crash. While I'm not intimately familiar with the particular environments you are using, I would suggest checking your .jsp code for any of this type of behaviour (for example two methods that call each other)
So, I had a similar error. For me, it was that I had a JSF project and I was messing around with the file extensions. To start with, I had all my web files with extension .jsp. This was working, but then I wanted them to be all .jsf, then after that I went all in on using .xhtml. In the process, my web.xml file changed to accomodate xhtml and jsf. Changing the web.xml file was fine. What got me the StackOverflowError was that I had index.xhtml with a ui.include tag pointing to header.jsf. So I had a xhtml file pointing to a jsf file. I had thought that web.xml would be able to handle this, but it did not, I got the StackOverflowError. So, to fix this, now all my JSF files have extension .xhtml, and nested ui:include tags point to .xhtml files.
On the flip side, though, the browser url can handle the index.jsp, index.jsf, index.xhtml just fine. So the web.xml (with servlet mappings for jsp, jsf and xhtml) handles the browser url just fine, but not for what my problem above highlighted.