Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!

Ben Souther

Sheriff
+ Follow
since Dec 11, 2004
Ben likes ...
Firefox Browser Redhat VI Editor
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
33
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ben Souther

Bear Bibeault wrote:Guess what: one of the other newer trends? Using JavaScript on the server instead of Java/Ruby/Python.

The times they are a-changing.



For an example, watch this video on node.js.
It's entertaining to see how fast Ryan Dahl is able to build an echo server while presenting his seminar.

This is an interesting time to be a web developer.
5 years ago
Jeanne,
The Subways up here don't have separate people but it might be better if they did.
Here is the typical script for a Subway trip for me.

What can I get for you?



Hi, can I have a 6" roast beef with lettuce, tomato's, and provolone cheese on the Italian bread?



What kind of bread?



Italian,



What kind of meat?



Roast beef.



Do you want cheese with that?



And so on, and so on until I've repeated every ingredient from the first sentence.
5 years ago

Welcome to blah blah blah.
My name is blah bha. I'll be taking your order today.
Would you like to try our special blah blah?


No. Thank you. I'd like a hamburger meal with a small drink.


Would you like cheese on that?


Wouldn't that be the cheeseburger meal?


I have to ask.


Understood. No Just the hamburger meal; no cheese.


Would you like to super-size that?


No thank you.


What size would you like that?


Small please.


We don't have small. We have medium, large,
and super-size.


Which is the smallest?


The medium.


Then I'll have that.


For thirty five cents more you can upgrade that to a large.
Would you like to do that?


No. Thank you. The small size will be fine.


What would you like to drink with that?


A bottled water, please.


We don't have bottled water. We have triple filtered water
at our fountain stations.


That will do.


What size would you like that?


Small, please.


We don't have small. We have medium large, and super size.


The smallest size you offer.


That would be the kiddie size.


Is that smaller than the medium?


Yes, but it's only available with the kid's meal.


Let's make that a medium.


Would you like to upgrade that to a large for twenty-five cents more?


No, please. Just a medium cup for me.


Would you like to try our new apple something-or-other dessert today?


No, thank you. Just the hamburger meal.


Okay, sir. I can do that for you.


Great.


Is that for here or to go?


For here.


Would you like salt, pepper, or ketchup with that?


No thanks, I can get that myself.


Do you have a rewards card with us?


No


Would you like to sign up for one today?


No, thank you.


It gives you 10% off your meals between blah and blah and you can
use your rewards points for free offers.


No thank you. I'd just like to pay for the hamburger meal and eat.


Okay, sir. I can do that for you. Would you like to donate a dollar to the blah blah fund today?


No, I gave at the office.


If you donate a dollar, you can put your name on a plate and hang it on our hall of fame bulletin board.


Sure, I'll donate a dollar. But don't bother with the plate, I'm running short on time now.


We can put anonymous on the plate for you.


What ever gets me out of here the fastest.


Okay, sir, I can see you're in a hurry. I'll get that for you now.


That will be $8.32. How will you be paying for that?


With this card.


Will that be credit or debit?


Credit.


Okay, sir. Hold on one moment while I get my manager to unlock the register.


...

Here you go, sir. Please sign here.


Sure.


Your number is 452, please wait at the next counter. Thank for coming to blah blah blah. We're always interested in hearing from our
patrons so that we can serve you better. Would you like to fill out our survey?


No, thank you. You did fine.


By filling out the survey, you enter yourself to win a free blah blah blah in our drawing.


Just the receipt please.


Thank you, sir, I hope you have a great lunch.


Thank you.



Jeesh....
5 years ago

Rahul Sudip Bose wrote:

Greg Charles wrote: Once a pup is touched by a human, its mother will generally never return to it.


Interesting. Can you tell me why do they do that ? Perhaps one could wrap cloth or bag around their hands before they help.




There is no need to help.

The moms need to leave the pups on the sand in order to hunt so they can feed them and so the pup can sleep.
The best way to help is to A) leave them alone and B) keep your dogs on leashes when you go to the beach, even after hours.
6 years ago

Saurabh Pillai wrote:They are very cute and adorable. Where is this park?

I think they are too young to swim.



The park is in Plymouth, MA.

I think they're born ready to swim.
This one is probably little more than a day old (judging by the umbilical cord).
6 years ago
Mothers will often leave the newborns on the beach at dusk while they go off to hunt.
(One of the many good reasons never to let your dog off its leash when at the beach).

We almost stepped on this guy while walking at one of the parks in Plymouth last week at the end of the day.
Another couple who came across it before we did kept trying to 'put it back in the water'. :/




6 years ago
Have you looked at the logs to see if the servlet wasn't able to be deployed?
7 years ago
Are you able to hit that component with a browser?
If so, then the web portion is OK, and the problem is in the client.

Likewise, you can test the client code by aiming it at URL that you know works.

7 years ago
The book in the link provided by sourabh girdhar is very old and outdated.

This link covers the custom class loaders used in Apache Tomcat (one of the most popular servlet containers today).
http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html

In it, you'll see that there is a separate link for each application within the server but nothing is mentioned about having a separate loader for each servlet.

A more fun way to learn about class class loaders is to put some print statements into a web app and start hitting it.
The following line will print the classloader information for the current class to the logs (or console depending on how your container is configured)


I just did this in a small test app. I put the statement in two servlets and then ran them.




From the output, you can see that both servlets are using the same classloader.
This makes sense because, in Tomcat, you can not reload a single servlet. You have to reload the entire app if you change a servlet.
With modern JEE programming, you probably wouldn't want a container to reload a single servlet as many apps these days are built with frameworks that only have one servlet that acts as a controller. Often this controller holds references to other Java objects within the app. Reloading just the controller without the rest of the app could cause very hard to trace bugs.


An interesting note:
The Jasper JSP engine used by Tomcat does create separate classloaders for each JSP.
This makes sense because JSPs need to be able to be reloaded whenever a change is made to them.

To print the classloader information in a JSP


The results after pasting that line into two different JSPs and hitting them:



Also, if you hit a JSP, and then update the code in it and hit it again, you'll see that a new class loader gets created:
7 years ago

Chanakya Gupta wrote:Summing up from Dieter and Sourabh,

- any part of the webapp can access this sessionid
(with access to request and event)



The part in the parenthesis is important here.
A ServletContextListener, for example, would not be able to access a session.
Likewise the init method in a servlet has no way to access any session information because servlets can be configured to be loaded when the container starts up, before any actual requests have been made.

7 years ago
You're selecting every name in the table and then comparing them in your Java code.
Why not build a select statement that looks for the exact username and password entered by the user.

If you have an empty resultSet, then you know there was no match.
7 years ago
+1 to both of the previous responses.

Just to reiterate, the servlet spec was designed from day one with to be multi-user / multi-threaded so, as long as you avoid some of the common issues (primarily the use of instance or non-final static variables) your app -- at least the front end-- will automatically be multi-user. If you're app works with a shared resource such as a relational database, then you'll have to consider what could happen if two people try to access it at the same time.

Like Malatesh said, have fun with some simple stuff first.
7 years ago
I know that iText can be used to create PDFs in memory to be streamed to the browser.
This might be desirable for smaller PDFs but, for larger ones, you might prefer to stream them to a file and then stream that file to the browser.

I've been able to stream PDFs to current browsers without knowing the content length. In the app I'm working on, I don't need to support older browsers so I'm not sure which ones required the content length header. I do know that this issue is covered in "iText In Action" by Bruno Lowagie along with some workarounds.

Last note: the current version of iText requires you to either buy a commercial license or comply with the terms of the GNU Affero Public License. Something you should understand before releasing an app/site with this library.

7 years ago
You don't send the session id to the server. Let Tomcat create them for you.
If there is a session id in the URL and Tomcat can't match it up to an existing session in memory, it just assumes that it is expired and ignores it.
7 years ago