Problems with Taglibs

G

gwoodhouse

Hello all,

Please help me! Im so tired of having taglibs in one way or another
trying to stop me doing some serious programming!

I'm getting this error:
javax.servlet.ServletException: javax.servlet.jsp.JspException:
Content is not allowed in prolog.

I have: "WEB-INF\lib\standard-1.1.2-patched.jar" in my buildpath.

The part of the code its having trouble with is in my very first page
with this:
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp" %>

which links to taglibs.jsp:
<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="c-rt" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<%@ taglib prefix="html" uri="http://jakarta.apache.org/struts/tags-
html" %>
<%@ taglib prefix="html-el" uri="http://jakarta.apache.org/struts/tags-
html-el" %>
<%@ taglib prefix="bean" uri="http://jakarta.apache.org/struts/tags-
bean" %>
<%@ taglib prefix="bean-el" uri="http://jakarta.apache.org/struts/tags-
bean-el" %>
<%@ taglib prefix="str" uri="http://jakarta.apache.org/taglibs/
string-1.1" %>

Now i know this exact same source code works for other people who are
using it as a base, so i must assume this is some sort of
configuration problem.

Could someone pretty please tell me what this error message can be
caused by because i can't find any way to fix it.

Thanks in advance to any guru's out there that can help me

Graeme
 
G

GArlington

Hello all,

Please help me! Im so tired of having taglibs in one way or another
trying to stop me doing some serious programming!

I'm getting this error:
javax.servlet.ServletException: javax.servlet.jsp.JspException:
Content is not allowed in prolog.

I have: "WEB-INF\lib\standard-1.1.2-patched.jar" in my buildpath.

The part of the code its having trouble with is in my very first page
with this:
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp" %>

which links to taglibs.jsp:

I think that the following line(s) may be causing your problem:
<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

You may be trying to reset the page headers after some output is
already written, it does not usually work...
 
L

Lew

I think that the following line(s) may be causing your problem:


You may be trying to reset the page headers after some output is
already written, it does not usually work...

I do not understand how those lines reset page headers after output is already
written. How is it that they do that?

Just about every JSP I've written for the last seven years begins with
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
(quoted from my current project verbatim)

Not a one has the error the OP described.
 
G

gwoodhouse

In response to GArlington:

From my understanding of the logic behind include statements, they are
preprocessed to create the whole "page" from its component includes,
which is then interpretted later in the proccess.

We use this default include on each of our (main) pages to save us
having to include the doctype and taglib directives all the time. As i
said, this same code is used by many other people in the company and
they have no problems.

Again after playing with this for a while i gave up and started again
and now no longer have this problem. Have to say i would love to be
able to solve this however as ive had it happen to me more than once!
I dont like having to resort to the microsoft method of configuration
fixing (ie, wiping and reinstalling).

Hopefully this thread will hang around for someone to eventually
answer! (Hopefully!)

Thanks again for your input lew, your not looking for a job are you?
Would save me alot of time to be able to walk across the office to ask
you rather than post to the group :)

Graeme
 
L

Lew

In response to GArlington:

From my understanding of the logic behind include statements, they are
preprocessed to create the whole "page" from its component includes,
which is then interpretted later in the proccess.

We use this default include on each of our (main) pages to save us
having to include the doctype and taglib directives all the time. As i
said, this same code is used by many other people in the company and
they have no problems.

Again after playing with this for a while i gave up and started again
and now no longer have this problem. Have to say i would love to be
able to solve this however as ive had it happen to me more than once!
I dont like having to resort to the microsoft method of configuration
fixing (ie, wiping and reinstalling).

Hopefully this thread will hang around for someone to eventually
answer! (Hopefully!)

Thanks again for your input lew, your not looking for a job are you?
Would save me alot of time to be able to walk across the office to ask
you rather than post to the group :)

I realized two things from your post. One is that gwoodhouse == graeme. The
other is that it isn't the two lines <%@page... and <!DOCTYPE...> that caused
the problem /per se/ but that they're in an included file. Now I understand
GArlington's point, that it was those lines *in an included JSP* that cause
trouble, maybe.

In one of my current projects I have JSPs that have
<%@ include file="/WEB-INF/jspf/navmenu.jspf" %>
near the top of each JSP.

navmenu.jspf begins
<%@page contentType="text/html" pageEncoding="UTF-8"%>
but does *not* have the DOCTYPE declaration.

Does that work for you?
 
L

Lew

In response to GArlington:

From my understanding of the logic behind include statements, they are
preprocessed to create the whole "page" from its component includes,
which is then interpretted later in the proccess.

We use this default include on each of our (main) pages to save us
having to include the doctype and taglib directives all the time. As i
said, this same code is used by many other people in the company and
they have no problems.

This is a misapprehension of the nature of the DOCTYPE directive. Have you
ever done "view source" on generated HTML? The DOCTYPE is not there, is it?

That's why your include doesn't let you include DOCTYPE - DOCTYPE just isn't
part of the page in that sense.

<%@include> doensn't include the text of the included JSP in an HTMLish way -
it includes it prior to compilation of the JSP. Thus you get two <DOCTYPE>
directives, I guess, which causes the emission of prolog information twice,
which generates the error message you saw.

I might have reasoned this one wrong in some of the details, but the fact
remains that including DOCTYPE doesn't work.
 
M

Mark Space

Lew said:
This is a misapprehension of the nature of the DOCTYPE directive. Have
you ever done "view source" on generated HTML? The DOCTYPE is not
there, is it?

I think I must misunderstand. You mean "View->Source" from a browser?
DOCTYPE sure as heck is present. It's the first thing in the document.

I assume you must mean view source from somewhere else?
 
A

Arne Vajhøj

Lew said:
You assume incorrectly.

I just again, as I did before my prior post, open up www.lewscanon.com
with Firefox and did a "view source". No DOCTYPE present. Sure as heck.

<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
out.println("Hello world !");
%>

Tomcat 5.5 gives me:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
Hello world !

so it seems to to depend on something.

Arne
 
L

Lew

Arne said:
<%@ page contentType="text/html;charset=UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%
out.println("Hello world !");
%>

Tomcat 5.5 gives me:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
Hello world !

so it seems to to depend on something.

Well I certainly learned something new from that. Now I know that lacking a
DOCTYPE is not universal, and I can check that assumption at the door.

The site I used was off the 'Net, not from a local Tomcat. There's one
difference right there.
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top