• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PrintWriter's println not working properly for me

 
Roshni Singhania
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Can anyone please provide me any hints as to why following piece of code is not working as I think it should?



So in the output on browser, I just get "Start End". That's it.

I'm coming back to Servlets and JSP after a big break of around 4-5 months, and I tried and tried and I'm not able to figure out why it's not printing in the loop or the str variable outside the loop. So kindly help me realize what I've done wrong here. I'll really appreciate that!

Thanks in advance!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pretty mysterious alright.

If this was my problem the first thing I would do is use the browser "view source" to see exactly what has been transmitted. Sometimes the peculiarities of HTML markup can conceal the real problem. Firefox browser is great for debugging because of the ease in viewing headers and the HTML as a DOM.

Bill
 
Roshni Singhania
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. Ya, I didn't think about that "View Source" before you mentioned. So I tried it just now. And in that also, funnily, I see the same thing. "Start End". I tried "View Source" in Mozilla Firefox, Avant and IE. Mozilla and Avant show the same thing in the source "Start End" and IE gives some access denied type error.

Any more suggestions please? I'm totally lost here.
 
Pradip Bhattacharya
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roshni,

I tried your code on Apache Tomcat 6.0 and its working. I had passed three parameters and I am getting this output

Start
grid_z: 30

grid_y: 20

grid_x: 10

grid_z: 30
grid_y: 20
grid_x: 10

End


The java file used is



The html file used is




 
Roshni Singhania
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pradip,

Yes that way it'd work. I got to know what mistake I was doing in my program. A friend brought it to my notice. In my JSP page, I'd given this servlet's link AND on the onclick event of the link, I was extracting this link's name and submitting the same form (in which this link is put), through JavaScript code.. so we figured what was actually happening was (if we're not mistaken) that two requests were going to the same servlet (via link and via form submitted) and links don't have request parameters it seems, correct me if I'm wrong. So we're still not sure, but we think it could be some sort of concurrent access problem.

I can post the JSP here, if anybody is interested in seeing this scenario (and then explain it to me )

Thanks to all those who replied!
 
Pradip Bhattacharya
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
roshni post your JSP code
 
Jhakda Velu
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I think the line before "End" is getting printed and its just blank, which is making her feel tis not getting printed(test this by initializing "str" as something other than blank). Her html form is not submitting properly and control is not going into while loop as her Enumerator is empty.

Jhakda
 
Roshni Singhania
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Here's the JSP code I was trying. I know this is not proper way, but I was just doing some R&D with that link there and got this unexpected output. Without that link, everything will work fine. With that link, two requests go to the servlet, one having some request parameters, and the other without any. Correct me if I'm wrong.

 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the <a> outside the form and let us know
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic