• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PrintWriter's println not working properly for me

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
roshni post your JSP code
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the <a> outside the form and let us know
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic