Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Eddy Lee Sin Ti

Ranch Hand
+ Follow
since Oct 06, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Eddy Lee Sin Ti

Hi,

Check this out, it might be helpful.

JavaRanch
Hi vijay,

Can you post up your class implementation code? It might have something to do with the package accessibility.
13 years ago
Hi Mag,

For add.jsp, your code might have useBean action too if you would like to retrieve back the data user entered, maybe for repopulating the form due to validation errors. It will depend on how you want to structure your code.

Cheers.
13 years ago
JSP
Hi Mag,

You can always invokes any reachable Java methods from within JSP scriptlet. If you are using jsp:useBean standard action to populate your Java Bean, it will store your Java Bean in the specific scope with the specified name you give. Also it will create a scripting variable using the id you given to the action.

For example,

<jsp:useBean id="userBean" class="domain.User">
<jsp:setProperty name="userBean" property="userName" value="${param.userName}" />
</jsp:useBean>
<%

// Using the scripting variable
out.println(userBean.getUserName());

// Default is page scope for your Java Bean
// So, you can retrieve your Java Bean using the following too

domain.User myUser = (domain.User)pageContext.getAttribute("userBean");
%>


Hope I understand your question correctly. Cheers.
[ November 02, 2006: Message edited by: Eddy Lee Sin Ti ]
13 years ago
JSP
Congrats. Waiting for your part III result.

Cheers
Flying colour result. Congrats.
Hi,

You want to pass the control to a particular jsp after the servlet finish processing or you just want to invoke a jsp and get the result back to servlet. Try to describe more, it might helps.

Cheers.
13 years ago
In your JSP, you can use application.getRealPath("/"). In your servlet, use the ServletContext.getRealPath("/").

One thing to note is that not all containers deploy your application by exploding them into certain directory. Some is using the WAR/EAR file as a whole.
13 years ago
As another thought, you can also use env-entry element in your deployment descriptor to define the environment variable and use JNDI to load them in runtime.

And even more fun if you want to experiment with MBeans to manage your resources like parameters.

Check this out: Mbeans and Tomcat
13 years ago
Hi,

For reading servlet configuration parameters, you can use the ServletConfig object to retrieve. For reading web application general parameters, use ServletContext instead.

I don't recommend to use catalina.bat to pass in parameters using java program arguments. Firstly, the security manager of the container might prohibit you from getting or setting the property. You will get an SecurityException if you do so. Next, it might require a different approach when your application migrate to other containers. You might also have maintenance issue when there are lots of parameters to configure.

What kind of properties you referring to? If these are application/domain specific parameters, usually it is better to put them in database.

Hope this helps. Cheers.
[ November 01, 2006: Message edited by: Eddy Lee Sin Ti ]
13 years ago
Hi, Timotius

The idea of servlet is to extend the capability of the web server to do specific processing based on the action that user specified, in this case can be determined from the servlet path in the url. Database connection is internal to the application and use only by the application components and not to be served to the end user over http, assuming you are using HttpServlet.

Any MVC/Model2 or other architectural guru will tell you to place only the database access code in the model or in the persistence layer, but not to mix them up in the presentation code or business logic components.

And to make some other points of why you shouldn't even think about DBPoolServlet and DBConnectionServlet are that the instances of servlet are managed by the container and you cant be sure which one your code will get.

So, my humble opinion is generally no pros. tons of cons.

Hope this helps. Cheers.
13 years ago
As far as I aware of, it is a container specific configuration.
13 years ago
The cached connection will become stale and throw exception when you try to do some database operations. You should explicitly open and close the connection whenever it is possible. By using some connection pooling data source, open connection means obtaining an opened connection from the pool and close is to return the connection back to the pool. The pool can be configured to invalidate the stale connection and recreate them.
13 years ago
Well, jsp:useBean might meet your need. What it does is that it will auto populate your Javabean from the http request parameter. Of course, some naming conventions has to be followed.

Hope this helps. Cheers
13 years ago