Hello. I'm very new at JSP. I'm trying to make a page navigator thing with an include statement like everyone does with PHP. So I have three files. I know it's way too much for something so simple, but I just wanna try things out. I'm using Eclipse and, unfortunately, eclipse keeps giving me this error when I run the program:
org.apache.jasper.JasperException: /index.jsp(11,0) The value for the useBean class attribute nav.MainNav is invalid.
So, I'm guessing the problem has something to do with how I delcared the beans...can I use java classes that extend other generic classes in JSP? And if I can, how would I go about doing that?
Navigator.java
package nav;
import java.util.*;
public class Navigator<T> {
/*
* Collection of valid pages
*/
private Set<T> pages;
/**
*
* @param pages
*/
public Navigator(Set<T> pages) {
this.pages = pages;
}
/**
* Adds a page to the set (if it's not already in the set)
* @param page
* @return true if the pages was added, false otherwise
*/
public boolean addPage(T page) {
return pages.add(page);
}
/**
*
* @param page
* @return true if the page was removed, false otherwise
*/
public boolean removePage(T page) {
return pages.remove(page);
}
/**
* Checks if a page is in the set of valid pages
* @param page
* @return true if the page is in the set, false otherwise
*/
public boolean isLive(T page) {
return pages.contains(page);
}
}
MainNav.java
package nav;
import java.util.*;
public class MainNav extends Navigator<String> {
/*
* MainNav instance
*/
private static MainNav n;
/**
*
* @param pages
*/
private MainNav(Set<String> pages) {
super(pages);
}
/**
*
* @param pages
* @return
*/
public static MainNav getNav() {
if (n == null)
n = new MainNav(new HashSet<String>());
return n;
}
}
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" %>
<%@ page import="nav.*" import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="MainNav" class="nav.MainNav" scope="request" />
<%!
MainNav n;
String currentPage, reqPage;
%>
<%
n = MainNav.getNav();
n.addPage("news.html");
n.addPage("about.html");
%>
<div id="na">
<a href="index.jsp?display=news.html"></a><br/>
<a href="index.jsp?display=about.html"></a><br/>
<a href="index.jsp?display=bad.html"></a>
</div>
<div id="body">
<%
reqPage = request.getParameter("display");
if (reqPage == null)
currentPage = "news.html";
else
currentPage = n.isLive(reqPage) ? reqPage : "error.html";
pageContext.include(currentPage);
%>
</div>
</body>
</html>