Here's my scenario...My homepage link is
local/proj/admin-home
when I browse in another link like
local/proj/registration/organization-registry
but on that page when I hover my mouse in another link the link gives me
local/proj/registration/list
But this link must be
local/proj/list
So I noticed that when I browse to the link local/proj/registration/organization-registry all of the links in that page also starts with local/proj/registration/ but it must be /local/proj/ only...
here's my xml file
<servlet>
<servlet-name>admin-home</servlet-name>
<servlet-class>web.HomeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>admin-home</servlet-name>
<url-pattern>/admin-home</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>list</servlet-name>
<servlet-class>ViewRegisteredServlet.RegisteredOrganizationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>list</servlet-name>
<url-pattern>/list</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>organization-registry</servlet-name>
<servlet-class>web_registration.OrganizationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>organization-registry</servlet-name>
<url-pattern>/registration/organization-registry</url-pattern>
</servlet-mapping>
You was apparently using a relative link. A relative link is a link which does not start with the scheme (e.g. http://), nor with a forward slash / which would take you to the domain root.
list
Such a link is relative to the current URL (as you see in browser's address bar). So it's basically pointing to the resource in the same folder.
You actually need to go one folder up:
list
Or, better, make it domain-relative, so that you don't need to mess with links whenever you move resources around.
list
This all has nothing to do with your servlet mappings. This is just a basic web development concept.
See also:
Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP
Related
When using Apache Tomcat, It will not serve me my external CSS stylesheet called CSS.css. Here is a picture of its location:
When I try to access it from home.jsp using this:
<link rel="stylesheet" href="${pageContext.request.contextPath}/CSS.css" type="text/css" >
nothing happens.
Also if I go to my browser and type in localhost:8080/myappname/CSS.css, It still doesn't find it.
I have researched this for a while and I seem to have done everything right. If anyone has an idea on why this isn't working for me that'd be great!
Try by renaming the file CSS.css to CSS1.css and re-deploy the application.
If it worked then rename CSS1.css back to CSS.css
I fixed it. All I had to do was add this to web.xml:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/css/*</url-pattern>
</servlet-mapping>
And I put all my CSS files in a folder in web app called css
Note that all CSS (and all javascript) files must be outside the WEB-INF folder. They have to be in a directly that can be accessed publicly .
Is it possible to run html and xhtml on the same page? I am using jsf and need to integrate it in a template.
if you really need to give them the .html extension, then you'd need to change the default suffix to .html as well. Add the following entry to web.xml to achieve that:
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.html</param-value>
</context-param>
I'm new to primefaces.I want to set up a theme that i dowloaded from the primefaces site. I added this code to web.xml
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>casablanca</param-value>
</context-param>
and i put the casablanca.jar in the /web-inf/ directory but still doesn't work
I have a Java EE application that I am building with Spring and Maven. It has the usual project structure. Here is a bit of the hierarchy.
MyApplication
src
main
webapp
WEB-INF
layout
header.jsp
styles
main.css
I want to include that CSS file in my JSP. I have the following tag in place.
<c:url var="styleSheetUrl" value="/styles/main.css" />
<link rel="stylesheet" href="${styleSheetUrl}">
When I deploy the application, the CSS page isn't being located. When I view the page source, the href is /MyApplication/styles/main.css. Looking inside the WAR, there is a /styles/main.css. However, I get a 404 when I try to access the CSS file directly in the browser.
I discovered that the reason for the issue was the Dispatcher Servlet mapping. The mapping looks as follows.
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I imagine the Dispatcher Servlet doesn't know how to handle the CSS request. What is the best way to handle this issue? I would rather not have to change all of my request mappings.
You need to configure Spring to handle the static resources (CSS, JS, images) separately from servlet requests to your app. To do this, configure your Spring config to map requests to static files via a separate top level directory (e.g. "static"):
<!-- Where to load static resources (css, js, images) -->
<mvc:resources mapping="/static/**" location="/" />
Then change your JSP to use the path /static/styles/main.css.
Note, convention dictates you name your "styles" directory to "css".
Add the following in web.xml
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
and use the following to include your css
<link rel="stylesheet" href="styles/main.css">
Someone at the office threw me this weird-yet-interesting question.
If I have something like this in a web.xml (either app' file or container's file)
<welcome-file-list>
<welcome-file>something.html</welcome-file>
</welcome-file-list>
and the thing has another page in a subfolder that can be used so I change it...
<welcome-file-list>
<welcome-file>subfolder/something.html</welcome-file>
</welcome-file-list>
¿Should the second option work? Thanks!
Answering to myself just to let it in the record.
Yes, it can be done. The address bar shows the context URL without the subfolder specified in the welcome-file directive. But it works fine.