Ciao a tutti,
ho un problema .
Ho una pagina dove faccio visualizzare un lista e per ogni nome c'è un link che mi porta ad una altra pagina.Questo link contiene l'id del nome cliccato .
Il problema sta che quando clicco su questo link mi va in errore e nella console mi scrive
GRAVE: ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'id' on 'class net.roseindia.Utente: Error setting expression 'id' with value '[Ljava.lang.String;@bfed5a'
24-giu-2011 12.12.08 org.apache.struts2.components.Form evaluateExtraParamsServletRequest
Qua sotto vi metto le pagine (nella parte java ho tolto i metodi get e set delle variabili )
Spero che qualcuno mi possa aiutare
strust.xml
visualizza.jspcodice:<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <include file="struts-default.xml"/> <package name="default" namespace="/" extends="struts-default"> <action name="Utentess" class="net.roseindia.Utente"> <result name="input">/insertData.jsp</result> <result name="SUCCESS" >/insertSucces.jsp</result> </action> <action name="add" method="add" class="net.roseindia.Utente"> <result name="input">/insertData.jsp</result> <result name="SUCCESS" >/insertSucces.jsp</result> </action> <action name="vis" method="vis" class="net.roseindia.Utente" > <result name="input">/insertData.jsp</result> <result name="SUCCESS">/visualizza.jsp</result> </action> <action name="editUser" method="edit" class="net.roseindia.Utente" > <result name="input">/insertData.jsp</result> <result name="SUCCESS">/insertData.jsp</result> </action> </package>
Utente.javacodice:<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib uri="/struts-tags" prefix="logic" %> <%@taglib uri="/struts-tags" prefix="s" %> <!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> <h1>Lista Utenti</h1> <table border="3px"> <tr> <td>Id</td> <td>Username</td> <td>Password</td> </tr> <s:iterator value="Mylist2"> <tr> <td><s:property value="id" /></td> <td><s:property value="username" /></td> <td><s:property value="password" /></td> <s:set name="id" value="#id"></s:set> <td><s:url id="editUtente" action="editUser"><s:param name="id" value="id"></s:param></s:url><s:a href="%{editUtente}">edit</s:a></td> </tr> </s:iterator> </table> </body> </html>
codice:import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class Utente extends ActionSupport { private int id; private String username; private String password; private String profilo; private ArrayList<String> myList ; private ResultSet myList2 ; private ArrayList<Profilo> listaprofili ; private Connessione con = new Connessione(); private Connection c = null; private Statement stmt= null; public Utente() throws Exception { c = con.getCon(); stmt=c.createStatement(); this.myList2 = lista(stmt); System.out.println("Utente!!!!!!!"); listaprofili = new ArrayList<Profilo>(); Profilo p = null; p = new Profilo("1","ADMIN"); listaprofili.add(p); p = new Profilo("2","DIP"); listaprofili.add(p); } public Utente (int i,String n, String p) throws Exception { this.id = i ; this.username = n ; this.password = p ; } public String execute(){ System.out.println("excutee!!!!!!!"); return "SUCCESS"; } public String add() throws Exception{ System.out.println("metodo add!!!!!!!"); try{ c = con.getCon(); stmt=c.createStatement(); if (username.equals("daniele")){ addActionError("errororororor"); return "input"; }else{ stmt.executeUpdate("INSERT INTO utenti (nome,password) VALUES('"+getUsername()+"','"+getPassword()+"')"); //this.myList2 = lista(stmt); return "SUCCESS"; } }catch(Exception e){ System.out.println("Eccezione : "+e.getMessage()); } return "SUCCESS"; } public String vis() throws Exception{ try{ System.out.println("visualizza!!!!!!!"); c = con.getCon(); stmt=c.createStatement(); this.myList2 = lista(stmt); }catch (Exception e){ System.out.println("Eccezione : "+e.getMessage()); } return "SUCCESS"; } public String edit(){ System.out.println("edit!!!!!!!"); // HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get( ServletActionContext.HTTP_REQUEST); // String user = request.getParameter("id"); // // Map parameters = ActionContext.getContext().getParameters(); // System.out.println(parameters.get(request.getParameter(user))); //HttpServletRequest request; this.id = 1; this.username = "pippo"; this.password = "pippo"; return "SUCCESS"; } public ArrayList<Utente> getMylist2() throws Exception{ ArrayList<Utente> lista = new ArrayList<Utente>(); System.out.println("Get Mylist2!!!!!!"); try{ while(this.myList2.next()){ Utente u = new Utente(this.myList2.getInt("id"),this.myList2.getString("nome"),this.myList2.getString("password")); lista.add(u); } }catch(Exception e){ System.out.println(e.getMessage()); } return lista; } }

Rispondi quotando