Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9227385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:03:58+00:00 2026-06-18T05:03:58+00:00

I have this problem: in my sql database I have a table Utente with

  • 0

I have this problem: in my sql database I have a table Utente with the primary key IDUtente that is of type INT and is Auto Incremental.
in the db I have:

ID|Name|....
1|Name1|....
2|Name2|....

in the Java servlet I read data from the database and I serialize data with Gson in this way:

Gson gson = new Gson(); 
String lista = gson.toJson(utenti);
request.setAttribute("lista", lista);
request.getRequestDispatcher("GestioneUtenti.jsp").forward(request, response);

and here it’s ok because the string lista it’s equals to:

[{"idUtente":1,"username":"a","password":"a","nome":"a","cognome":"a","dataNascita":"dic 12, 1988","telefono":"3200769667","indirizzo":"a","citta":"a","luogoDiNascita":"a","abbonamentiATempo":0,"abbonamentiAPunti":0,"dataIscrizione":"dic 12, 2000","posizione":"socio","email":"a"},{"idUtente":2,"username":"b","password":"b","nome":"b","cognome":"b","dataNascita":"giu 25, 1960","telefono":"3474213142","indirizzo":"b","citta":"b","luogoDiNascita":"b","abbonamentiATempo":0,"abbonamentiAPunti":0,"dataIscrizione":"mar 11, 2001","posizione":"non socio","email":"b"}]

In my JSP page now I have to deserialize the string and I do this in this way:

<%String lista = (String)request.getAttribute("lista");
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();                         
Type listType = new TypeToken<ArrayList<Utente>>() {}.getType();
ArrayList<Utente> users = gson.fromJson(lista, listType);
for(int i=0;i<users.size();i++){
out.print("<tr>");
out.print("<td>"+users.get(i).getIdUtente()+"</td>");
out.print("<td>"+users.get(i).getNome()+"</td>");
out.print("<td>"+users.get(i).getCognome()+"</td>");
    out.print("<td>"+users.get(i).getPosizione()+"</td>");
    out.print("<td>"+users.get(i).getTelefono()+"</td>");
 }

The problem is that The IDs printed are always equals to 0! Why?
If it is necessary I’ll write also my class Utente!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:04:00+00:00Added an answer on June 18, 2026 at 5:04 am

    Why are you serializing utenti to JSON, putting it on the request then deserializing it in the JSP?

    Just put the list in the request and extract the List as you are the string – no GSON needed.

    Now if you were putting this across the wire to the client, THEN I can see the need for GSON but not in your particular usage case.

    You’re entire operation is taking place within the server, so there is no need for you to serialize the utenti list instance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a SQL Server database table that consists of user id, some numeric
this is my problem: I have a table in my mysql database which contains
I'm getting crazy with this problem: I have got some Oracle SQL-Reports to redesign
I'm a beginner at SQL and have this fairly easy conditional problem: Every installation
I have 5 tables in MySQL, but i believe this is a SQL problem
I have this problem that I can ref a button for control it. I
I have a MS SQL 2005 database with a table Test with column ID
I have a database with a table that contains Name and CompanyName . They
I have used this statements to populate jcombobox from MySql database table using Hibernate
I have a SQL Server 2008 R2 database table with 12k address records where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.