Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link

Alex Pi

+ Follow
since Jan 08, 2013
Alex likes ...
Netbeans IDE Java
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alex Pi

Bear Bibeault wrote:As you are using the JSTL and EL why are you bothering with useBean and setProperty at all?

You have catched me. :) I learn JSP, and i still didn't know JSTL.
I know how to use scriptlets but i do first steps (only couple days) with EL.

Perhaps it will be better to ask how could i set nested properties without using scriptlets.
9 years ago
I've got 2 JavaBean-classes:

Then i retrieve request parameters in JSP:

How can i set properties for person.address (nested property)? (person.firstName & person.secondName are correct).
9 years ago
Please, remove <html> </html> and others tags, because when you making including navigationbar.jsp you receive nested <html><html></html></html> tags and so on... It's wrong. And don't confuse JSP with JavaScript.

Bear Bibeault wrote:You need to use an HTTP uRL to address the image, not the file protocol.


OK. What have i got at the moment?!

As a result i have such a link:

I understand this is a wrong approach because each odd client will receive html code and each even client will receive only one png image. (I call this servlet twice and produce a different responce).

This instance only for my training and this approach is good for only one client (for my own education).
But I'd like to pass to a client the link to the image file (not the repeated request to the servlet).
When i do like that i receive NullPointerException:

I have such a situation:

What do i wrong?
(Sorry for corrections)
9 years ago
I have BufferedImage buffer.
I know how to send this image to a client: And it works.

But i'd like to save this image to file and send to a client link to the file.
My following code doesn't work:

I don't see any png-file on the HD (in the application directory) and the link: <img src=\"out.png"></img> leads nowhere. I'd like to have an embedded image in html.

When i use above code i have next html:

when i click the src link (i see page source) i have next message:
The address wasn't understood
Firefox doesn't know how to open this address, because the protocol (c) isn't associated with any program.
9 years ago
I changed my code:

Hurra! I received what i wanted:
Value is: 60
Thread name is: http-thread-pool-8080(4)

Value is: 20
Thread name is: http-thread-pool-8080(5)

Value is: -20
Thread name is: http-thread-pool-8080(1)

I wanted to receive "Race condition"...
9 years ago
Oh my Got... Thank you, my fault.... I wanted to create misleading behavior... i wanted to check simultaneous access...
9 years ago

Nam Ha Minh wrote:You have a delayed response because you wrote:


inside the servlet's processRequest() method.

Yes. But it's not so easy.
I modified my code like that:

(4 requests from different tabs) produced following result:

Value is: 50
Thread name is: http-thread-pool-8080(5)

Value is: 50
Thread name is: http-thread-pool-8080(4)

Value is: 50
Thread name is: http-thread-pool-8080(1)

Value is: 50
Thread name is: http-thread-pool-8080(2)

It looks like i have different instances for each request-thread, and different threads for each request. Is it correct?
9 years ago

Ulf Dittmer wrote:

Will i have only one instance of servlet for all requests or N-instances of servlet for N-requests?

You will have one instance, so the "a" field will be shared between all threads, whether they happen concurrently or not.

But why do i have always the result 50.
I thought i will subtract 50 every time. (the result will be 50, 0, -50, -100... so on)
9 years ago
I am a newbie. I do first steps in servlets.

I use NetBeans IDE 7.3 & GlassFish Server 3.1.2.

I open my JSP several times in a few tabs (Firefox) and send a request to my servlet. Every time i have a result 50. Every next time when i wait a response i need to wait (i guess there is a delay because a servlet is sleeping. But i thought so... There is only one servlet class. Will i have only one instance of servlet for all requests or N-instances of servlet for N-requests? And if i have separated threads for each request (a new thread for a new request) - why i have delay with response? (every time i need to wait longer)?
In fact i expected to have an concurrent access problem (100 -50 -50 -50...)
9 years ago
It's not for a real-life programming
I just wanted to find out some opportunity to check my SCJP 6 answers
I assumed, maybe there exists some real-time list of objects with attribute: this object is accessible or not accessible for GC.
9 years ago
Is it possible to find out programmatically how many objects are eligible for garbage collection and print out their quantity?
9 years ago

Winston Gutkowski wrote:

But, that said, you need to understand that there are two main phases that apply to these things, and they are almost completely independent.

1. static stuff is run/initialized when a class is loaded; and that happens when it is needed by the JVM, and it is usually only done ONCE.

2. Non-static stuff is run/initialized when each object is created, which may happen never, once, or a million times in a program.

Personally, I've never worried about it in 11 years of writing Java. If I create an object, or call a static method, I assume it's done; and I try to avoid situations where the order in which it's done makes any difference.

About the only thing that you really need to know is that constructors are run in hierarchical order (ie, Object first), which basically makes sense if you think about it.



Many thanks you, Winston!
My problem was to see the hierarchical order of building of objects (and classes loading as well, of course).
I don't have any industrial experience in Java (may to say in any programming). I just want to pass the SCJP 6 test and to find work.
9 years ago

Henry Wong wrote:
I believe the correct sequence, according to the JLS, is that static initialers should be executed in the order that the class is loaded. And that the order that it is loaded, is the order that it is needed. For example, if you access a static variable of the subclass, the subclass will be loaded only (the super class will not be loaded).

All hierarchy will be loaded:

A: static a1
B: static b1
B: second static block
main: C: c1 static
BUILD SUCCESSFUL (total time: 1 second)

No. You are wrong. Sorry.
9 years ago

Winston Gutkowski wrote:
Well, first up, I'm not sure how much education you're going to get from these contrived examples.

I need to know it for SCJP 6, I guess.
Now, after scrolling entire output i can see the correct sequence of output.
9 years ago