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>

I figured it out myself. I had to remove this line

<jsp:useBean id="MainNav" class="nav.MainNav" scope="request" />

I also had to stop using eclipse because I tried running the program without that line and the i got an error about not being able to find the file. Unless it was just the server...

So, since I found out I don't need to turn java classes into beans...what is the point of a java bean?

Do NOT use scriptlets in JSP.
And learn something about Java in general before trying JSP.

Lastly, don't blame Eclipse and the server for your incompetence. Blame yourself for not understanding what you're doing and why you're getting errors.

wow, that doesn't help at all. thanks.

i tried this on my own server, that's how i figured out the problem...and i tried the same solution in eclipse and it blew up. so i think blaming eclipse/the server is the right thing to do.

and what's wrong with my java? i haven't used the language for a year and i was just trying things out.

the problem in this case is not with Eclipse, nor (if it works outside of Eclipse) with your application, but with you.
You don't understand how to use Eclipse, and you blame Eclipse for that rather than your incompetence in using it.

So read that documentation, try some of those tutorials, and see what you learn.

JUST LET ME HAVE MY CAKE

it was eclipse...a defect

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.