Help: jsp:include error???

E

eeyimaya

Hello,


I am studying with "Core Servlets and Java Server Pages Volume1" on
Servlets and JSP.And I use Resin for
examples in the book. (The problem is at chapter 13.1)

I have one jsp and one html file as below:
C:\resin\webapps\WebModule\WhatsNew.jsp
\WEB-INF\web.xml
\WEB-INF\aaa.html
WhatsNew.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<TITLE>What's New at JspNews.com</TITLE>
<LINK REL=STYLESHEET HREF="JSP-Styles.css" TYPE="text/css">
</HEAD><BODY>
<TABLE BORDER=5 ALIGN="CENTER"><TR><TH CLASS="TITLE">What's New at
JspNews.com</TABLE>
<P>
Here is a summary of our three most recent news stories:
<OL><LI><jsp:include page="WEB-INF/aaa.html"/></OL>
</BODY></HTML>

aaa.html:
<B>Bill Gates acts humble.</B> In a startling and unexpected
development, Microsoft big wig Bill Gates put on an open act of
humility yesterday.
<A HREF="http://www.microsoft.com/Never.html">More details...</A>


Here aaa.html is wanted to ben shown in the WhatsNew.jsp.
But when I call the page as http://localhost/WebModule/WhatsNew.jsp.
it gives the error given below. If I put the aaa.html to the WebModule
folder as the WhatsNew.jsp it works. But I wanted aaa.html cannot be
seen by clients.Author also states this as:
"Finally, note that you are permitted to place your pages in the
WEB-INF directory. Although the client is prohibited from directly
accessing files in this directory, it is the server, not the client,
that accesses files referenced by the page attribute of jsp:include.
In fact, placing the included pages in WEB-INF is a recommended
practice; doing so will prevent them from being accidentally accessed
by the client (which would be bad, since they are usually incomplete
HTML documents)."

Error is:
java.io.FileNotFoundException: /WebModule/WEB-INF/aaa.html
at com.caucho.servlets.FileServlet.service(FileServlet.java:245)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:113)
at com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:129)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherImpl.java:476)
at com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherImpl.java:345)
at com.caucho.jsp.PageContextImpl.include(PageContextImpl.java:807)
at _jsp._whatsnew__jsp._jspService(/WhatsNew.jsp:18)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.pageservice(Page.java:571)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
at java.lang.Thread.run(Thread.java:534)


What is wrong?
Please help...
Thanks.....
 
K

kaeli

Hello,


I am studying with "Core Servlets and Java Server Pages Volume1" on
Servlets and JSP.And I use Resin for
examples in the book. (The problem is at chapter 13.1)

I have one jsp and one html file as below:
C:\resin\webapps\WebModule\WhatsNew.jsp
\WEB-INF\web.xml
\WEB-INF\aaa.html

Why are you putting an html file in your WEB-INF directory?
Generally speaking, files meant to be served to a client shouldn't go there.
WhatsNew.jsp:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

Put a URL in that doctype or it throws some browsers into quirks mode. That's
usually not a good thing.
But when I call the page as http://localhost/WebModule/WhatsNew.jsp.
it gives the error given below. If I put the aaa.html to the WebModule
folder as the WhatsNew.jsp it works. But I wanted aaa.html cannot be
seen by clients.

Then put it in a password protected directory that is a subdir of your webapp
(webmodule) directory and has normal web permissions. WEB-INF is NOT for
hiding html files.
If you're using Apache, look at .htaccess files. You can even protect a few
files in a given directory, but protecting the whole directory is simpler.

Note that the JSP, once compiled, is often moved by the server to some other
location. How the server handles relative links to resources can be tricky.
Note this line from the error message:
at _jsp._whatsnew__jsp._jspService(/WhatsNew.jsp:18)
See how the file name changed? The location probably did, too.
I'm not familiar with Resin, but try putting the file in a directory, like
C:\resin\webapps\WebModule\myProtectedHTMLfiles
then linking like you are now with the directory name. If it interprets links
relative to the application root, add a leading slash.
(/myProtectedHTMLfiles/myfile.html)

HTH

--
--
~kaeli~
Why do they lock gas station bathrooms? Are they afraid
someone will clean them?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top