Li ho messi nello stesso package, ma non funziona lo stesso!
ecco i codici:
mrBean.java:
codice:
package pac;
public class mrBean
{
private String ip = "";
private int nr = 0;
private String pageR = "";
public void setIp(String nrIP)
{
ip = nrIP;
}
public String getIp()
{
return ip;
}
public void setNr(int tentativi)
{
nr = tentativi + 1;
}
public int getNr()
{
return nr;
}
public void setPagina(String pagina)
{
pageR = pagina;
}
public String getPagina()
{
return pageR;
}
}
SessinoTag.java:
codice:
package pac;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.*;
public class SessionTag extends TagSupport {
---->public mrBean bean = new mrBean();
public int doStartTag() throws JspException
{
try {
HttpServletRequest req = (HttpServletRequest)pageContext.getRequest();
HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
JspWriter out = pageContext.getOut();
Enumeration attributi = null;
//apro la sessione solo se esiste
HttpSession session = req.getSession(false);
String pagina = req.getRequestURI().toString();
attributi = session.getAttributeNames();
int nrAttributi=0;
//controllo se esiste verfificando gli attributi memorizzati
while(attributi.hasMoreElements()){
attributi.nextElement();
nrAttributi++;
}
//almeno nome e pwd devono esserci, altrimenti non esiste
if (nrAttributi < 2)
{
response.sendRedirect("../index.jsp?paginaRichiesta="+pagina);
return SKIP_PAGE;
}
else {
String nome, pwd = null;
attributi = session.getAttributeNames();
//controllo se č stata selezionata una pagina da raggiungere
if (pagina.compareTo("null")!=0) {
//se si allora controllo se č una pagina amministrativa e chi č il richiedente
//se č l'admin OK, altrimenti nonentri!
-------->String page=bean.getPage();
if ((nome=attributi.nextElement().toString()).indexOf("admin")==-1 &&
(pwd = session.getAttribute(nome).toString()).indexOf("admin")==-1 &&
pagina.indexOf("admin")!=-1) { response.sendRedirect("../nonentri.jsp");}
}
attributi = session.getAttributeNames();
while(attributi.hasMoreElements()){
nome = attributi.nextElement().toString();
pwd = session.getAttribute(nome).toString();
out.println("- "+ nome + ": " +pwd+ "
");
out.println("</p>");
}
}
return EVAL_PAGE;
}
// rethrow IOException to JSP container as JspException
catch( IOException ioException ) {
throw new JspException( ioException.getMessage() );
}
}
}