Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!

Mark Wilcox

+ Follow
since Sep 01, 2004
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 Mark Wilcox

As the earlier post suggests - you cannot submit Java objects via HTTP form posts. Once you've displayed the results in a browser, it does not know anything about Java objects. All HTTP can do is send text - this is why Web Services (in their most common form) use XML. If it was easy to send binary encodings over standard HTTP - Web Services would be different (you'd end up with something like RMI) because binary is much more efficient than plain text.

Basically you must either uses the Session object (essentially a HashMap that maintains its values for a given user's session - where the J2EE container manages a session, usually via cookie for you automatically) OR you must persist the state yourself - for example as hidden form fields or cookies or storing in a database (where you store the record key in a cookie).

Usually people go with Session objects unless you know you're dealing with very large amounts of data in an object.

13 years ago
The web application is going to have at the minimum need the following elements:
1 - it's going to need the client side classes for your EJB. The J2EE spec has a client-jar element in ejb-jar.xml just for this, but hardly anyone uses it. Optionally you can just copy the entire JAR into your Web tier.
2 - The Web Tier will need to be able to access the JNDI context of the J2EE server (needs to know server name and probably requires a username/password)
3 - You will need to know JNDI name of your EJB
The problem is that you've put your count object as a global variable:

public class DemoSFEJB implements SessionBean {
static final boolean verbose = true;

private SessionContext ctx;
private transient Properties props;
private int count = 0;

instead you should write your demoSelect like so:

public String demoSelect()
throws RemoteException
int count = 0;

return("SF : " + count);

Then you should see the behavior expecting.

What's probably happening is that BEA is saving resources and caching the SessionBean.

This is a tricky one to answer because in Java, unlike PHP or ASP, there's not just a single way to architect a Web application.

The general consensus is that you should use a pattern called "MVC" which stands for Model View Controller and is adopted from non-Web client-server development (and a key component of Smalltalk).

The idea being that you have a central object (a Java servlet) that manages basic application framework information such as authentication and application state objects (the model piece). It then directs application logic flow to a view component.

That sounds simple enough - but the trick is choosing a framework . And Java Web frameworks are a bit like the joke about "standards" - there's so many to choose from. It seems one can't wake up without discovering yet another new Java Web framework.

On one level they are simple to generate on your own, after all most are simply a Java servlet, that manage state in a Java bean (a Java class that just manages data and business logic) and then displays HTML (either via JSP or framework specific template files).

The 3 most popular (Based on my 'scientific' method of trolling on Javalobby, JavaRanch and plus personal experience):
Apache Jakarta Struts (has the most adoption and most tools support)
Apache Velocity (really a general templating engine)
Apache Tapestry (cool part is that it uses standard HTML files for templates and leverages HTML attributes to do dynamic populate them)

I have a tendency to always pick Struts because I know it best. Velocity intrigues me for its simplicity.

But if I was starting from scratch - I'd go with Tapestry because I like it's use of HTML and (totally non-objective) - I'm friends with Howard Lewis Shipp who's the developer/maintainer of Tapestry .

13 years ago
Unique Id for what?

In general, I strongly discourage using any system's identifier for any purpose outside of it's stated purpose. The reason is that systems change and they're not expecting you to be using their session id for your system.

And so they change their behavior - which then may break your system.

Thus to be less risky - don't use the Java session identifier for your own unique identity. Instead generate your own unique ids. The simplest approach (assuming you're doing this for a database) - is to create a function that simply returns a counter (start with 1 and each request increments that number).

Make it static and synchronized to minimize chances of two users with the same id.

And then use a database or text file to remember the last count when your system shutsdown.

13 years ago
All classes for servlets need to go into WEB-INF/classes

In Eclipse, if your go Properties for your project (right click on project name), go to Java Build properties, source tab.

Then change Default Output folder.