*
The moose likes JSP and the fly likes JSP Directive Visible on Webpage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Directive Visible on Webpage" Watch "JSP Directive Visible on Webpage" New topic
Author

JSP Directive Visible on Webpage

Erik Zimmerman
Greenhorn

Joined: May 02, 2011
Posts: 4
My first post here...

I have a JSP page with a directive at the top of the page. It looks like this:

<%@ page language="java" import="java.sql.*"
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"
trimDirectiveWhitespaces="false"%>

(Note I have also tried putting the above code all on one line)

The shows code shows as plain text when the JSP page is deployed to the server. It is hidden as expected on my development machine.

What could cause this? A configuration file somewhere?

Using the website "validator.w3.org" I get the following error returned about the above line when run from the server:

1. Error Line 5, Column 1: character data is not allowed here

<%@ page language="java" import="java.sql.*"

You have used character data somewhere it is not permitted to appear. Mistakes that can cause this error include:
* putting text directly in the body of the document without wrapping it in a container element (such as a <p>aragraph</p>), or
* forgetting to quote an attribute value (where characters such as "%" and "/" are common, but cannot appear without surrounding quotes), or
* using XHTML-style self-closing tags (such as <meta ... />) in HTML 4.01 or earlier. To fix, remove the extra slash ('/') character. For more information about the reasons for this, see Empty elements in SGML, HTML, XML, and XHTML.

So... this is telling me that the leading character "<" is not valid???

The really strange part of it is that when I use the code clean up feature in the site, it returns the same value for the "invalid" line.

What could be wrong here?

Erik
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Sounds like the server may not be processing the page as JSP and is simply serving it as plain text. Are other JSP mechanisms on the page evaluated?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

P.S. The wc3 validator is for validating HTML not JSP. Of course it's going to complain.
Erik Zimmerman
Greenhorn

Joined: May 02, 2011
Posts: 4
Bear Bibeault wrote:Sounds like the server may not be processing the page as JSP and is simply serving it as plain text. Are other JSP mechanisms on the page evaluated?


Thanks for the reply. It is quite possible that the server is not processing the page as JSP. There are a few scriptlets with calls in to the database to display some data. Those are not working. What troubles me the most is that I can make a simple page of two lines with something like "Hello" and "GoodBye" and it pages fine. As soon as I add the directive at the top of the page, it fails. In Google Chrome I see all of the html as plain text. In IE the html formats the text correctly but the SQL statements don't render correctly on the page. The SQL is probably not executing (my guess).

Are there any good tools to validate the JSP like the html tool that I was using? What do you suggest?

Please ask more questions if you need. I will provide as much information as possible.

Thanks again,

Erik
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

First to back way, way up, there should be no scriptlets on your JSP pages. That's technology that been discredited for almost ten years now. But that's not your current problem. But very soon, you are going to need to update your JSP knowledge.

Now onto the current issue: your description of what is going on is disorganized and not well thought out.

When a page gets to the browser, does a View Source show the original JSP page or not? Simple as that.

Is the setup on the server the same as on your development machine? (same version of servlet container and so on)?
Erik Zimmerman
Greenhorn

Joined: May 02, 2011
Posts: 4
Bear Bibeault wrote:First to back way, way up, there should be no scriptlets on your JSP pages. That's technology that been discredited for almost ten years now. But that's not your current problem. But very soon, you are going to need to update your JSP knowledge.

Now onto the current issue: your description of what is going on is disorganized and not well thought out.

When a page gets to the browser, does a View Source show the original JSP page or not? Simple as that.

Is the setup on the server the same as on your development machine? (same version of servlet container and so on)?


Admittedly, I am just starting out in Java, JSP and the like. Much of what I am doing is based on samples provided by a friend who hasn't worked with JSP recently. That said, this is my problem, and I just want get this to work and make the customer happy.

I'll try to describe my troubles clearly. Thank you for your patience so far.

Yes, the "View Source" looks the same as the original source. In fact it shows the scriptlets.

No, unfortunately, my development environment is far different from the server. Mine is Windows XP Pro and my IDE is Eclipse v 3.2. The server is running Fedora Red Hat. I thought that Java was pretty much platform independent. Guess I was wrong there.

Thanks again,

Erik
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Erik Zimmerman wrote:Yes, the "View Source" looks the same as the original source. In fact it shows the scriptlets.

That clearly shows that the pages are being served directly without being interpreted as JSPs.

No, unfortunately, my development environment is far different from the server. Mine is Windows XP Pro and my IDE is Eclipse v 3.2. The server is running Fedora Red Hat. I thought that Java was pretty much platform independent. Guess I was wrong there.

What does this have to do with Java being platform independent? None of what you list here is pertinent. What servlet containers are being used? Are you sure that the remote server is even running a servlet container?
Erik Zimmerman
Greenhorn

Joined: May 02, 2011
Posts: 4
Bear Bibeault wrote:
Erik Zimmerman wrote:Yes, the "View Source" looks the same as the original source. In fact it shows the scriptlets.

That clearly shows that the pages are being served directly without being interpreted as JSPs.

No, unfortunately, my development environment is far different from the server. Mine is Windows XP Pro and my IDE is Eclipse v 3.2. The server is running Fedora Red Hat. I thought that Java was pretty much platform independent. Guess I was wrong there.

What does this have to do with Java being platform independent? None of what you list here is pertinent. What servlet containers are being used? Are you sure that the remote server is even running a servlet container?


Do think that the fact that the pages are being interpreted as JSPs is something that I can pin on the hosting company, because as of now, they are telling me that there are scripting errors?

Thanks again,

Erik
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Scripting errors would cause errors, not the page to appear as its source. Something is fishy...
Mike Zal
Ranch Hand

Joined: May 04, 2011
Posts: 144

How is your server configured? What type of servlet container are you using? It sounds like you may be deploying the JSP file to a simple web server instead of a servlet container.


OCJP6, OCWCD5
Dieter Quickfend
Bartender

Joined: Aug 06, 2010
Posts: 506
    
    4

Are you sure JSP is supported by your hosting provider?


Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JSP Directive Visible on Webpage
 
Similar Threads
http error404
<%@ page language = "java" contentType = "text/html"; charset = ISO-8859-1" %> - Error from Netbean
HFSJ 2nd edition, Page 346
help on controller jsp
Session Keeps Changing