S
Skijor
How is it possible to load a relative resource from a .jsp file that
was forwarded a ServletRequest using RequestDispatcher from a servlet?
Example:
1) set up a simple servlet:
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-
INF/tmp.jsp");
dispatcher.forward(request, response);
}
}
2) define a simple jsp file (tmp.jst):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<link href="<%= getContextPath() %>/css/tmp.css" rel="stylesheet"
type="text/css">
</head>
<body>
FOOBAR
</body>
3) include a simple css file (in root/css) which turns the text in the
<BODY> red:
* {margin: 0; padding: 0;}
body {
font-family: verdana, arial, sans-serif;
font-size: 3em;
text-align: center;
color: red;
}
problem: this css file never gets loaded using forwarding (FOOBAR
never appears red)
was forwarded a ServletRequest using RequestDispatcher from a servlet?
Example:
1) set up a simple servlet:
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-
INF/tmp.jsp");
dispatcher.forward(request, response);
}
}
2) define a simple jsp file (tmp.jst):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<link href="<%= getContextPath() %>/css/tmp.css" rel="stylesheet"
type="text/css">
</head>
<body>
FOOBAR
</body>
3) include a simple css file (in root/css) which turns the text in the
<BODY> red:
* {margin: 0; padding: 0;}
body {
font-family: verdana, arial, sans-serif;
font-size: 3em;
text-align: center;
color: red;
}
problem: this css file never gets loaded using forwarding (FOOBAR
never appears red)