GunnaSatria

October 7, 2008

Simple JSP Part 4

Filed under: Java — Tags: — gunnasatria @ 8:20 am

As i promised a long.. long time ago.. 
i will write an example of using java beans in jsp pages.
The idea of this scenario is so you as a java web developer not being mixed up between HTML scripts and Java scripts.
So, if in the previous example we embedded some java instructions in HTML scripts then for this tutorial we will separate both.

Supposed you have this usual Java class acting as our first created java beans. 
package pages;

public class HelloWorld {

public String getMessage(){
           return “Hello Word”;

and then you have a regular HTML in a JSP file like below,

<html>
<head>
<title>Simple JSP Part 4</title>
</head>
<body>
</body>
</html>

and let’s name it message.jsp

Now, the idea is to display message from our HelloWorld class to our jsp page. How we will do it?
Add below java instruction between body tag in our message.jsp

<%

pages.HelloWord hw = new pages.HelloWorld();
out.println(“message is: “+hw.getMessage()); 

%>

To putting it all together, below is the full code.

<html>
<head>
<title>Simple JSP Part 4</title>
</head>
<body>

<%

pages.HelloWord hw = new pages.HelloWorld();
out.println(“message is: “+hw.getMessage()); 

%>

</body>

</html>

Then you will see a nice hello word message.
This is just a tiny example of how usefull java beans will be. The other benefit is if separate our logic into our java class, then we will able to test it first and will not having much difficulties in debuging compared to when we join our java instructions in our jsp pages.
But.. there is always a backside of this. If you want to update your java class, then you have to restart your web server to get it work.

So… have a nice try n error.

January 7, 2008

Simple JSP part 3

Filed under: Java — Tags: , , — gunnasatria @ 2:12 am

Now we are trying to connect our web application to a database. I use Northwind database here as an example database.
For you who don’t know what Northwind is, it is a sample database given if you install MS Access. I am sorry for non Windows user, but if you follow below tutorial you should also do it in another database like MySQL or PostgreSQL.
(more…)

January 5, 2008

Simple JSP part 2

Filed under: Java — Tags: , , — gunnasatria @ 9:09 am

Our next tutorial is about handling user input. We will start with the most common input component which is text field.
Open your index.jsp and add new codes like below, (more…)

January 4, 2008

Simple JSP part 1

Filed under: Java — Tags: , , — gunnasatria @ 1:32 pm

This post is dedicated for you who want to start learning how to create a web application using Java using only simple JSP. I assumed here you already have Java basic knowledge. Please enjoy. (more…)

November 19, 2007

Hibernate Annotation Tutorial

Filed under: Java — gunnasatria @ 1:33 pm

As in my previous post, right now i’m working on a project that use Hibernate annotation. I feel great and really believe that i am making a right choice. So, i want to share my experience using it here. (more…)

October 30, 2007

What to choose?

Filed under: Java — gunnasatria @ 2:19 pm

I am now in the phase of design and analysis of a software project. So i have to choose what should i use in this project.
For the presentation layer my candidates are Tapestry 3.0.3(because i don’t want to use Tap 5 who is still in alpha), ZeroKode (based from my recent experience) and Webwork (which i use in my last project). (more…)

October 22, 2007

(Not) Simple JSF+Spring

Filed under: Java — gunnasatria @ 2:14 pm

I don’t know why but suddenly i want to take a look of this framework. So, i search some jsf tutorial and download jsf distribution framework (jsf 1.2) . I create a simple hello world project using my eclipse ide after following instruction from the tutorial i found. try running it using jetty 5 and the result is it didn’t work..
i found java.lang.NoClassDefFoundError: javax/el/ELResolver error. (more…)

October 17, 2007

ZK.. the next best thing

Filed under: Java — gunnasatria @ 2:30 am

I read about ZK in Matt Raible blog. This is one of the site i frequently read for new information about Java world other than theserverside.
So after taking a small look in their site, i decide to try it. I download the zk-bin-3.0.0-RC.zip package and ZK-devguide-3.0.0-RC.pdf yesterday and try it this morning. (more…)

Blog at WordPress.com.