jsp file is not reflecting the styles in bootstrap - css

I have jsp file and trying to load bootstrap.min.css there, both files(jsp and bootstrap) are in the same directory which is webapp and this is the code that I use to link jsp and bootstrap.css together.
<link rel="stylesheet" type="text/css" href="bootstrap.min.css">
But the jsp is not reflecting any style that the bootstrap contain and this is the problem that I got.
Resource interpreted as Stylesheet but transferred with MIME type text/html

The problem solved when I changed the code in the web.xml
<servlet-mapping>
<servlet-name>hotel-deals</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
to
<servlet-mapping>
<servlet-name>hotel-deals</servlet-name>
<url-pattern>/hotel</url-pattern>
</servlet-mapping>

Related

How to change the path of swagger-ui in spring-mvc

How can I change the path of swagger-ui so that it is not loaded on / but at /docs/
The simple solution recommended in some blogs would be to unpack swagger-spring-mvc-ui sources in webapps dir. But I search for a elegant solution where the webjar swagger-spring-mvc-ui is a dependency like all others.
Is there a reason why something like this doesn't work?
<!-- swagger api declaration -->
<servlet>
<servlet-name>ApiDeclarationServlet</servlet-name>
<servlet-class>com.wordnik.swagger.servlet.listing.ApiDeclarationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ApiDeclarationServlet</servlet-name>
<url-pattern>/api-docs/*</url-pattern>
</servlet-mapping>

How to get swagger-ui for wordnik/swagger-core sample java-jaxrs

I am new to swagger world. I downloaded the wordnki/swagger-core from github and deployed java-jaxrs sample. The url http:localhost:8080/api/api-docs/pet returns the response. I want to view this content in swagger-ui.
I added the swagger-ui directory contains needed js and html files. How to configure my web.xml to view this swagger-ui? so that I can configure my resource in swagger url as http:localhost:8002/api/api-docs.
You have to add following mapping in your web.xml
<servlet>
<servlet-name>DEFAULT_REST_SERVLET</servlet-name>
<servlet-class>{{your_dispatcher_servlet}}</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DEFAULT_REST_SERVLET</servlet-name>
<url-pattern>/v1/*</url-pattern>
<url-pattern>/api-docs/*</url-pattern>
</servlet-mapping>
hope this helps

Spring mvc 3.2 and extjs 4.1.3 : do I have to define mvc:resources mapping for al requestMapping path?

I have a problem using spring mvc 3 and extjs 4 or more precisely a problem of path when exjs try to load my controllers or my images.
The structure of my webapp is like this :
src
-- webapp
-- app
-- extjs4.1.3
-- css
-- icons
-- WEB-INF
-- jsp
app.js
I have a controller annoted like this
#RequestMapping(value = "/path/init.do", method = RequestMethod.GET)
It return a view name that match a jsp in my WEB-INF/jsp folder. This jsp load extjs files.
ViewResolver :
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
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>tiana Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/spring/application-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
</web-app>
Because my url pattern is "/", I had to make use of the mvc:resources magic tag available since spring 3.0.5 (approximatively) like this :
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/app/**" location="/app/" />
<mvc:resources mapping="/extjs-4.1.3/**" location="/extjs-4.1.3/" />
<mvc:resources mapping="/app.js" location="/app.js" />
I know it could be better if I place all those things in a resources folder. I would have to write only :
<mvc:resources mapping="/resources/**" location="/resources/" />
But I don't think it'll solve my problem
My jsp file is like this :
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>My jsp title</title>
<link rel="stylesheet" type="text/css" href='<c:url value="/extjs-4.1.3/resources/css/ext-all.css" />'>
<link rel="stylesheet" type="text/css" href='<c:url value="/css/myStyle.css" />'>
<script type="text/javascript" src='<c:url value="/extjs-4.1.3/ext-all-debug.js" />'></script>
<script type="text/javascript" src="<c:url value="/app.js" />"></script>
</head>
<body></body>
</html>
First of all I had to write the references to my resources files using jstl tags.
Without those tags, if I keep url like /myresource.xxx, the url will be
localhost:8080/myresource.xxx
And if I write myresource.xxx without the slash, it is
localhost:8080/mywebapp/path/myresource.xxx
But it works like this, any suggestion would be appreciated to skip the jstl dependency but it works.
My real problem is that my app.js will load extjs's controllers and for that it uses some kind of 'window.location' to construct the url. In my case, it will be
localhost:8080/mywebapp/path/app/controller/myController.js
but i'd like it to be
localhost:8080/mywebapp/app/controller/myController.js
I face the same kind of problem if I put an icon in my extjs files, the url will be
localhost:8080/mywebapp/path/icons/myIcon.png
and not
localhost:8080/mywebapp/icons/myIcon.png as expected.
I can solve this by adding
<mvc:resources mapping="/path/app/**" location="/app" />
<mvc:resources mapping="/path/icons/**" location="/icons" />
But I can believe that each time I define a new requestMapping in a Spring mvc controller, "path2" for example, I'll have to define a corresponding mvc:resources mapping.
I tried to define a global "baseUrl" javascript variable in my jsp file, prefixing the appFolder by this variable in the app.js file and prefixing all icons and things used in extjs code by this variable but it's not either acceptable.
What have I missed ? I googled a lot and I came to this "/" url-pattern and mvc:resources method (which seems very clean for spring mvc webapp) but I cannot solve my "uri" problem (I don't know how the path generated by the requestMapping is called in real english).
Thank you so much if you can help me and if not, thank you for your time
You can try to put all of your resources (i'm not sure which of your contents is a static resource) in:
-- webapp
--resources
-- app
-- extjs4.1.3
-- css
-- icons
-- WEB-INF
-- jsp
app.js
then you define a single mapping:
<mvc:resources mapping="/resources/**" location="/resources/" />
at this point you'll access the css folder for example using:
<c:url value="/resources/css/myStyle.css" />
and any other of your paths in the same way or you can try by using (but not tested):
<mvc:resources mapping="/**" location="/resources/" />
and i suppose you'll access your css folder:
<c:url value="/css/myStyle.css" />

Link/ include css in FreeMarker using Spring 3 MVC

I am currently trying to include a css file in my FreeMarker *.ftl. I also have configured a resource folder in my servlet config xml file.
<mvc:resources mapping="/resources/**" location="/resources/" />
But how can I access my css file from my FreeMarker template?
I simply tried the following but without success.
<link href="/resources/css/style.css" rel="stylesheet" type="text/css" />
The resource folder lies in the root of my spring MVC 3.0 application.
/web
/resources
/img
/css
/WEB-INF
/templates
My Servlet root is defined as:
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/web/*</url-pattern>
</servlet-mapping>
My FreeMarker files are lying in the templates folder.
I have found two solutions. One with spring macros and one without in my FreeMarker file.
The simplest way is to use it without macros:
<link rel="stylesheet" type="text/css"
href="/springmvc/resources/css/style.css" />
In this solution I have to define the complete path.
By using spring macros you have to lay your spring.ftl into your template directory and include it in each FreeMarker template where you like to use it.
<#import "spring.ftl" as spring />
<html>
<head>
<title>...</title>
<link rel="stylesheet" type="text/css"
href="<#spring.url '/resources/css/style.css'/>"/>
...
The spring macros can also be used for other things this blog gives a good overview.
You can try this,
<link rel="stylesheet" type="text/css" href="<c:url value="/"/>resources/css/style.css" />
At run time this code will return exact path.

web app web.xml error [duplicate]

This question already has answers here:
Getting error: The content of element type "web-app" must match,
(3 answers)
Closed 5 years ago.
I am getting an error in my GWT application being developed in Eclipse. It's in the web.xml file. Here's the error:
The content of element type "web-app" must match "(icon?,display- name?,description?,distributable?,context-
param*,filter*,filter-mapping*,listener*,servlet*,servlet-mapping*,session-config?,mime-mapping*,welcome-
file-list?,error-page*,taglib*,resource-env-ref*,resource-ref*,security-constraint*,login-config?,security-
role*,env-entry*,ejb-ref*,ejb-local-ref*)".
I have seen numerous posts about this and the problem is the order of the elements of the file, but that fix doesn't work for me (I have also tried putting all the <servlet-mapping> tags right after the corresponding <servlet>, it did not work either)
My web.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<servlet>
<servlet-name>dispatch</servlet-name>
<servlet-class>com.yachtcloser.server.DispatchServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>upload</servlet-name>
<servlet-class>com.yachtcloser.server.UploadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>download</servlet-name>
<servlet-class>com.yachtcloser.server.DownloadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>com.yachtcloser.server.LoginServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatch</servlet-name>
<url-pattern>/dispatch.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>upload</servlet-name>
<url-pattern>/upload.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>download</servlet-name>
<url-pattern>/download.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login.do</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Yc.html</welcome-file>
</welcome-file-list>
</web-app>
Are there any other ways of tracking this error; other files that are linked to this?
well, as per new format of DTD web-app tag might contains following tags.
<!ELEMENT web-app (icon?, display-name?, description?, distributable?,
context-param*, filter*, filter-mapping*, listener*, servlet*,
servlet-mapping*, session-config?, mime-mapping*, welcome-file-list?,
error-page*, taglib*, resource-env-ref*, resource-ref*, security-constraint*,
login-config?, security-role*, env-entry*, ejb-ref*, ejb-local-ref*)>
above mentioned icon, display-name, description, distributable....etc are in the same order as they have mentioned in the DTD file.
e.g. if you put description tag before display-name it gives error.
I deleted the file and pasted the text from the old one into a new file with the same name and now there's no errors.
Just for a reference: A SelectAll->Cut->Save->Paste->Save also fixes the problem. Probably there is a line ending character issue.
I followed the suggestion for "copy all" - "cut" - "paste" - "save" and this seemed to clear up the message. I found that in the "pasted" version all tabs had been converted to spaces.
So it seems that the web.xml validator in Eclipse does not like tabs.
The error itself gives you the clue. The order of the elements in your web.xml should follow the order specified in the error.
<displayname>
</displayname>
<description>
</description>
....... like this the elements should be in order as it says in the error.

Resources