Internet Explorer和JSP中的基本URL [英] Base URL in Internet Explorer and JSP
问题描述
Internet Explorer不支援HTML < base>标签,甚至其他浏览器都会这样做,当重定向发生在
servlets 到某些
.jsp 页面时有一些问题
请求调度。
添加 $ {pageContext.request.contextPath}
与每个URL
或 request.getServletPath()
CSS与图像的相对链接servlets转发可能会改变很多事情。此链接:浏览器可以'访问/查找CSS,图像和链接等相关资源时调用转发到JSP的Servlet
是否有更好的JSP方法/ servlets或它只是一个IE问题?
链接: HTML< base> TAG和本地文件夹路径与Internet Explorer
如果是IE问题:
1 。如何解决IE问题,因为上面的帖子无法给出有效的答案?
2.如何使用JSP / servlet解决它?
我的网站现在显示CSS和图片。
例如HTML输出是:
< base href =http:// localhost:8080 / Alpinema // >不适用于
< link media =all =stylesheettype =text / csshref =css / all.css>
它适用于Firefox和Chrome等其他浏览器。
我的JSP代码部分:
< head>
< base href =$ {fn:substring(url,0,fn:length(url) - fn:length(uri))} $ {req.contextPath} //>
< meta charset =utf-8>
< title> Alpinema.com< / title>
< link media =all =stylesheettype =text / csshref =css / all.css>
/ css?family = Merriweather | PT + Sans:700 | Nobile:400italic'rel ='stylesheet'type ='text / css'>
< / head>
< c: url>
来自JSTL的标记,以引用JSP文件中的CSS / JavaScript资源。通过这样做,您可以确保CSS / JavaScript资源始终相对于应用程序上下文(上下文路径)被引用。示例
index.jsp:
<%@ page language =javacontentType =text / html; charset = UTF-8pageEncoding =UTF-8%>
<%@ taglib prefix =curi =http://java.sun.com/jsp/jstl/core%>
<!DOCTYPE html>
< html>
< head>
< title> Some Title< / title>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8>
< link type =text / css =stylesheethref =< c:url value =/ css / main.css/> />
< script type =text / javascriptsrc =< c:url value =/ js / utils.js/>>< / script>
< script type =text / javascriptsrc =< c:url value =/ js / jquery-1.8.3.js/>>< / script>
< / head>
< body>
...
< / body>
< / html>
有关更多解决方案,请参阅我的答案:
在JSP中添加外部资源(CSS / JavaScript / images等)。
Internet Explorer doesn't support HTML <base> tag and even other browsers do, there are some problems when redirect takes place in
servletsto some
.jsppages for example
request dispatching.`
It's feasible to add ${pageContext.request.contextPath}
with each URL
nor request.getServletPath()
JSP relative links for CSS and images with servlets forwarding may change things a lot. This link : Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP
Is there a better approach with JSP / servlets or it's just an IE issue?
Link : HTML <base> TAG and local folder path with Internet Explorer
And if it is an IE issue:
1. how to fix the IE issue as the above post is unable to give a valid answer?
2. how to solve it with JSP / servlets?
My website is now showing CSS and images.
E.g. HTML output is:
<base href="http://localhost:8080/Alpinema/" /> is not working for
<link media="all" rel="stylesheet" type="text/css" href="css/all.css">
It works in other browsers like Firefox and Chrome.
My JSP code portion:
<head>
<base href="${fn:substring(url, 0, fn:length(url) - fn:length(uri))}${req.contextPath}/" />
<meta charset="utf-8">
<title>Alpinema.com</title>
<link media="all" rel="stylesheet" type="text/css" href="css/all.css">
/css?family=Merriweather|PT+Sans:700|Nobile:400italic' rel='stylesheet' type='text/css'>
</head>
Use <c:url>
tag from JSTL to reference CSS/JavaScript resources inside my JSP files. By doing so you can be sure that the CSS/JavaScript resources are referenced always relative to the application context (context path).
Example
index.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<title>Some Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="<c:url value="/css/main.css" />" />
<script type="text/javascript" src="<c:url value="/js/utils.js" />"></script>
<script type="text/javascript" src="<c:url value="/js/jquery-1.8.3.js" />"></script>
</head>
<body>
...
</body>
</html>
For even more solutions see my answer here:
Adding external resources (CSS/JavaScript/images etc) in JSP.
这篇关于Internet Explorer和JSP中的基本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!