File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes PrintWriter's println not working properly for me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "PrintWriter Watch "PrintWriter New topic
Author

PrintWriter's println not working properly for me

Roshni Singhania
Ranch Hand

Joined: Mar 11, 2007
Posts: 78
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

Joined: Mar 22, 2000
Posts: 12678
    
    5
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

Java Resources at www.wbrogden.com
Roshni Singhania
Ranch Hand

Joined: Mar 11, 2007
Posts: 78
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

Joined: Dec 05, 2008
Posts: 23
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





Pradip.B
Roshni Singhania
Ranch Hand

Joined: Mar 11, 2007
Posts: 78
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

Joined: Dec 05, 2008
Posts: 23
roshni post your JSP code
Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 166
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


If I become filthy rich, I'll sponsor research for painless dental treatment at Harvard Medical School. Thats why,I'm learning Java.I have 32 teeth, 22 are man made.
Roshni Singhania
Ranch Hand

Joined: Mar 11, 2007
Posts: 78
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

Joined: Dec 16, 2007
Posts: 151
Put the <a> outside the form and let us know


Cheers!
RSR
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PrintWriter's println not working properly for me
 
Similar Threads
Banner
HTTP status 500
Code Review - ChatServlet
Help with this code
Help with this code