0

I'm currently doing this tutorial, but the tutorial uses Glassfish as the server and I'm using Tomcat 7.0.22 as the server. I'm trying to include a header and a footer as .jspf files I only get this:

When it's supposed to look like this:

It only renders the page without including the header and the footer, also when I go to the category page (http://localhost:8080/AffableBean/category) it renders the page like this:

When it's supposed to look like this:

My webxml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <jsp-config>
        <jsp-property-group>
            <url-pattern>/index.jsp</url-pattern>
            <url-pattern>/WEB-INF/view/*</url-pattern>
            <include-prelude>/WEB-INF/jspf/header.jspf</include-prelude>
            <include-coda>/WEB-INF/jspf/footer.jspf</include-coda>
        </jsp-property-group>
    </jsp-config>
</web-app>

If I try to use a differente web-app tag like this one:

    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org    
    /TR/xmlschema-1/" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-
    app_2_4.xsd" version="2.4">

Only the index page will get rendered correctly but when I want to go to another page like

http://localhost:8080/AffableBean/category

I get a 404 error

Is it because I'm using Tomcat instead of Glassfish?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
rkrdo
  • 1,051
  • 1
  • 9
  • 15

2 Answers2

1

Something went wrong with your properties of your netbeans project. Everything looks fine to me. You can find an image here:

enter image description here

Please take the following steps and let me know if it provides a solution:

  • Create a new netbeans project
  • Copy the map 'view' from your old project directly under the directory 'Web pages'.
  • Delete the file 'category.jsp' and replace it with the original file from (solution 2, at the end of the page) http://netbeans.org/kb/docs/javaee/ecommerce/page-views-controller.html
  • Copy the map css from your old project and paste it directly under the directory 'Web pages'.
  • Copy 'header.jspf' and footer.jspf from your old project and paste it to the 'view' map.
  • Open your 'header.jspf and change the css include line to: < link rel="stylesheet" type="text/css" href="../css/affablebean.css" >
  • Open the clean 'web.xml' under 'WEB-INF', click on the 'XML' tab and paste http://pastebin.com/89nz4uLP.

Alternate solution: Example header.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
    <div id="header"> <span class="something">text here</span>
                <div id="banner">

                    <h1><a># Android</a></h1><br/>
                </div><br/>
    </div>
            <div id="menu">
                    <a href="index.jsp">Welcome</a>
                    <a href="#" class="none">|</a>
                    <a href="Register.do">Register</a>
                    <a href="#" class="none">|</a>
                    <a href="Newsflash.jsp">Newsflash</a>
            </div>

Include it where you need it in your webpage (jsp), by using

<jsp:include flush="true" page="header.jsp"></jsp:include>

As you see you don't need to re-add all the html in the header.jsp, just the part of the header.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kim
  • 1,764
  • 1
  • 11
  • 14
  • You are not really answering the question. You're basically telling "Sorry, it works for me with ``, I don't know the answer for `` and ``". – BalusC Nov 17 '11 at 19:57
  • Oviously he mentioned "I'm trying to include a header and a footer as .jspf files I only get this" (First screenshot). If he includes it that way, the header/footer should be rendered correctly since I took my example directly from my 'working depot shelf'. It's better taking the time to give an working alternative then just looking and skipping his question. Isn't it? – Kim Nov 17 '11 at 20:00
  • Yeah, I know I can use the tag, but I'm trying to avoid using those 2 lines by including the prelude coda tags – rkrdo Nov 17 '11 at 20:04
  • @Kim: your effort is much appreciated, but this does definitely not answer the OP's question. You're merely ignoring his concrete question/problem and not explaining why it fails and what the solution is. You'd better have posted a comment on the question wherein you suggest the `` alternative. If you earn at least 50 reputation, then you can also post comments on other's posts. – BalusC Nov 17 '11 at 20:06
  • @rkrdo: Did you tryout a .jsp file (delete de html/body etc) in place of a .jspf file? I've had issues with a .jspf file in the past when using it as a header. – Kim Nov 17 '11 at 20:25
  • @Kim that didn't work :(, I'll keep trying, so it doesn't have anything to do with me using Tomcat instead of Glassfish, maybe an incompatibility issue with the tags? – rkrdo Nov 17 '11 at 20:40
  • @rkrdo: Not really. Would it be possible to upload the full project so I can take a peek? – Kim Nov 17 '11 at 20:51
  • @kim sure https://github.com/rkrdo/example_netbeans , also if I use Glassfish as the server I have no problems – rkrdo Nov 17 '11 at 21:15
  • @BalusC I've edited my previous post, you were right. Hope I'm on the right 'path' :). – Kim Nov 17 '11 at 22:24
1

Change your web.xml header to:

<web-app version="3.0" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

See also: Is it possible to add jspf files to a jsp page without using jsp:include?

Community
  • 1
  • 1
John.K
  • 11
  • 1
  • I already have this as my web.xml header. But, I am getting an unexpected exception - https://stackoverflow.com/questions/25026495/cannot-find-resource-in-web-app-even-after-giving-correct-path – james Jul 29 '14 at 23:25