File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method showing different returns when declared on JSP or Servlet

 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have
on a Servlet which calls



when I call it from servlet, it only returns the first occurrence of the database, and twice(!) but when I call it from the same JSP that shows only the doubled result, then it shows up all of the users on the database.

Result calling from servlet:
1 thiago borges leobons thiago thiagoleobons@gmail.com 1234-5678 Americas, 10000 Rio de Janeiro RJ
Genaro de Carvalho, 2000 apto 302 Rio de Janeiro RJ
1 thiago borges leobons thiago thiagoleobons@gmail.com 1234-5678 Americas, 10000 Rio de Janeiro RJ
Genaro de Carvalho, 2000 apto 302 Rio de Janeiro RJ

result calling from JSP:

[1, thiago, thiagoleobons@gmail.com, 1234-5678, 1, thiago, thiagoleobons@gmail.com, 1234-5678, 2, admin, admin@gmail.com, 1234-5678, 3, leobons, leobons@gmail.com, 1234-5678, 4, leob, thi@gmail.com, 12345666, 6, zzzz, leobo@gmail.com, 12345666, 8, thithi, th@gmail, 12322333]

Actually, if you see the result on the JSP, the first result is actually always coming doubled, even with the same primary key, which to me makes no sense!

Thanks for your help

 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the code where you are invoking that function in your jsp, it will make us to understand the problem more clear.
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The scriplet on the bottom is for debugging purposes, when I uncomment the redirection, it sends me to the JSP that does show me the whole content of the user table on the database.

If you also want the whole method on the servlet:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64189
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you really not indent your JSP code?

Where's the servlet code that loops through the list showing different results?
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the JSP loops through the list using the tag <c:forEach>
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the servlet code? You said it worked differently when you called it from a servlet, so you should be able to show us that code too.
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the 2nd block of code in my 1st answer is the servlet code
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can see the loop on lines 4 and 5 of the JSP as I pointed out before (the forEach tag). As I also pointed out before, I put a scriplet on the bottom specially for checking out the answer I get when calling the same method from a JSP, not a Servlet.

 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But look. You said
when I call it from servlet, it only returns the first occurrence of the database


Apparently this doesn't mean that when you call that code fragment from a servlet, it only returns the first occurrence of the database. It must mean something else, since you don't actually have any examples of calling that code fragment from a servlet.

So what exactly does it mean? You're saying that code fragment works differently in two situations, but you've only showed us one, as far as I can see. You're going to have to do better at explaining the two situations.
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thiago Leobons wrote:I mean, what would be the point of people doing when they could just not answer, right?


There's a lot of people here that I don't waste my time answering. You aren't in that category, not yet anyway.
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:
Apparently this doesn't mean that when you call that code fragment from a servlet, it only returns the first occurrence of the database. It must mean something else, since you don't actually have any examples of calling that code fragment from a servlet.


But yes I do! It's on line 15 of my servlet's code
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I see what you mean. But I don't understand what you are comparing... your first version (the EL expression) is this horribly cumbersome code with nested c:forEach loops and your second version (the scriptlet) is no code at all; I don't see how you can say anything at all based on that code.

I would simplify the testing code and use the same tests for both versions.
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code on the scriplet calls the same method as I did on the servlet but it comes up with all the entities on the table, differently from the code that's formatted with what you call "horribly cumbersome". Let me know if you find a simpler way to format this table the way I want to.
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're saying that the code, when first executed, returns N records, and then when executed a second time, returns M records, where N and M are different numbers. You only need one line of code to produce N (instead of the 25 lines you have there) and likewise you only need one line of code to produce M, whereas you don't have any such code in what you posted.

So my suggestion is to change your code which tests your theory to do just that. Just those two lines of code.
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please consider only lines 04 (calling attribute from line 15 of my servlet) and line 36 (the results from this line show on the redirection page if you uncomment it) for simplicity sake.
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. But you weren't asking me to test your code, were you? Obviously I don't have a lot of the infrastructure needed to do that. I was asking YOU to do that test -- a line like line 4 which shows the size of the first version of the collection, and an identical line which shows the size of the second collection. Nothing more or less than that.
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put that on my first message.. I'll put that again in block code for you to see the result

Result calling from servlet:
1 thiago borges leobons thiago thiagoleobons@gmail.com 1234-5678 Americas, 10000 Rio de Janeiro RJ
Genaro de Carvalho, 2000 apto 302 Rio de Janeiro RJ
1 thiago borges leobons thiago thiagoleobons@gmail.com 1234-5678 Americas, 10000 Rio de Janeiro RJ
Genaro de Carvalho, 2000 apto 302 Rio de Janeiro RJ


result calling from JSP:

[1, thiago, thiagoleobons@gmail.com, 1234-5678, 1, thiago, thiagoleobons@gmail.com, 1234-5678, 2, admin, admin@gmail.com, 1234-5678, 3, leobons, leobons@gmail.com, 1234-5678, 4, leob, thi@gmail.com, 12345666, 6, zzzz, leobo@gmail.com, 12345666, 8, thithi, th@gmail, 12322333]


see that the code from servlet only brings up the two first results (which are "actually the same") or at least both have the same primary key

(I edited your post's format so that it didn't come out three times as wide as my screen - Paul C)
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that was the output from your code that was partly too complicated and partly invisible to me. Let me know when you have the output from the test which I suggested. If you don't understand what I suggested, then let me know and I will write the code for you.
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh wow.. thanks for the suggestion of taking the formatting out. It ends up that the addresses are not being created on the database and since the printing of the user values are linked to it by the varStatus on the nested loop, they're not showing.
still.. wonder why the array is coming from the bank with primary key #1 showing twice?
 
Paul Clapham
Sheriff
Pie
Posts: 20190
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you're getting somewhere now. Originally your theory was "servlets produce different data than JSPs" or something like that, and you seemed determined to prove that theory correct.

But when you're debugging, it's just as good to have a theory which you can prove to be incorrect. At least then you can check off something and say "This isn't the problem, then." That's why it's a good idea to produce the simplest possible test for a theory, even if it involves setting aside your existing code and writing a special test harness just for that theory. That makes it much easier to get rid of incorrect theories. Your code was far from being the simplest possible test, and as I suspected, it was leading you in the wrong direction.

I doubted your original theory from the start, or at least the version of it which I just stated. My (unstated) competing theory was "The second call produces different data than the first call." However it appears that's an incorrect theory as well, but I don't mind at all. The point isn't for me (or you) to be right, it's to find out what's going on.
 
Thiago Leobons
Greenhorn
Posts: 20
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wasn't determined to show it was true I was just repeating it because it seemed to me that people didn't get what I was trying to explain, but yeah you're right, that was a silly mistake. I'm just still having the issue of showing the first line of the table twice. any idea on why this should be happening?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic