Openbook

IE issue: The back button and the HTML form

Posted by: manoj1987 on: December 4, 2009

Recently, while working on my first JSP project i noticed that, while testing a form in Internet Explorer8, i noticed that when you navigate back to a form using the back button(either the one you coded or the one provided by IE browser)the form fields remained uncleared, except the password field(Thank God!). My form is one that updates an Ms-Access database and duplicate entries in field corresponding to the primary key of my database would throw an error.

The reason why IE has not cleared the form field is because of its caching technique. Googling on this problem led me to this Microsoft webpage.

I tried the solution prescribed by them  but was not successful. I even tried calling a Javascript function when submit button is pressed.This function submits the form values to the intended destination page and then resets the form fields.This technique did not succeed either.

So my verdict is please switch over to Mozilla Firefox, because it was very developer friendly and user friendly. Firefox rocks!!

The  following  sites may also help you:

* Clear a form on a web page after the details have been submitted….

* Clear cache of form’s field

* self clearing forms

JavaBean in JSP : a simple tutorial

Posted by: manoj1987 on: November 20, 2009

Hi !

Purpose of this tutorial : To give the reader a better understanding of using Java beans in JSP.

Advantage : This tutorial serves as an instant learning tutorial for those who would want to learn about using  Java bean in JSP.

Sources : The code used in this short tutorial has been extracted from www.jsptut.com

What is a Java Bean ?
Java bean are classes written in the Java programming language conforming to a particular convention. A Java bean has a set of properties that can be read or changed. It is also possible to discover the properties a bea has available, which well suits beans for modeling all kinds of real world things that can also be described as a set of properties.

Illustration:

What we will be doing?

We will create a simple html page(getName.html) that is used to get user’s name, email and age.  When we submit that data, it invokes a JSP page(SaveName.jsp) that inserts the user entered data into a bean. We provide a “click here to continue” link in that same page, which when clicked would invoke another JSP page (NextPage.jsp) that retrieves the data that was inserted into the bean and displays it!

The implementation is simple and straight forward!

Tools needed:

I have tested this code successfully in Tomcat 6.0 configured suitably with jdk1.5.0_14 and jre1.5.0_14.

code :

getName.html


SaveName.jsp


NextPage.jsp


Keep the above files in your webserver directory. My webserver classpath is C:\Tomcat 6.0\webapps\ROOT\ . Now we must develop a Java code to store the values obtained from the form. We then compile that Java code to obtain its “class” file. This class file is the real beauty of Java. Its contents look somewhat junk type when viewed using any editor. And that means that its not easy to hack your data from it(say, a password was sent from the form).

The contents of the Java code are very important. We define a Java class with fields “username”,”email” and “age” which must correspond exactly to the field names in getName.html. We define two types of methods in this Java code viz, a “setter” method and a “getter” method.

In simple,

* The setter method is a method that starts with the keyword “set” followed by the field name. In our example the setter methods would be setUsername,setEmail and setAge. Now compare this with the field names in getName.html. The only point you must note here is  the first letter, following “set”, is in uppercase. These setter methods insert the user entered data into the corresponding variable names into the bean.

At this point, by reasoning you should have understood that a bean is an instance of the Java class(correct me if i am wrong).

* The getter method is a method that returns the values stored in the javabean, to the entity that invoked it(NextPage.jsp in this case). The getter methods are named in the same way as setter methods except that the keyword “set” is replaced by “get”. So now we have getUsername,  getEmail, getAge

The java code is shown below:

UserData.java

Now compile the above Java code and place the code inside a folder named “user” because we have declared a java package by that name. This folder (along with the java class)should be placed in the following location:

<Application_Base\application_name>\WEB-INF\classes\

For me its :

C:\Tomcat 6.0\webapps\ROOT\WEB-INF\classes\

If the folder “classes” is not present then create one.

That is it invoke the getName.html file from the browser after starting Tomcat server and see the code in action. JSP rocks!

Output:

See the output here , here and here.

What I have not explained here?

I have not explained the meaning of the java bean tags in the jsp code given about. Their meanings and pupose are quite intuitive,if not just google to find more info on them.

How could i make use of this idea?

You can use the idea gathered from this tutorial for designing a user login page using java beans. Creativity has no bounds.

References:

Quicksort-better explained

Posted by: manoj1987 on: November 15, 2009

A picture speaks a 1000 words, but a video speaks more than 1000 pics.

And yes the above video is a perfect example to that statment.

Quicksort better explained visually!

Tags:

Xournal

Posted by: manoj1987 on: November 13, 2009

Xournal is an application for notetaking, sketching, keeping a journal using a stylus. It is free software (GNU GPL) and runs on Linux (recent distributions) and other GTK+/Gnome platforms. It is similar to Microsoft Windows Journal or to other alternatives such as Jarnal, Gournal, and NoteLab.

Download Xournal

Xournal

Related links :

Linux for the aged

Posted by: manoj1987 on: November 13, 2009

A new computer aimed at people aged over 60 who are unfamiliar with PCs and the internet has been unveiled.

An interesting news by BBC on the new Linux fork designed specially for old aged people and aptly named SimplicITy .

Read on and watch the video here.

Additional info:

Microsoft patents sudo !!!

Member

Thank me

Rate

NewsGator

Subscribe in NewsGator Online

Popular Downloads of this month

get your ubuntu9.10 here

get your ubuntu9.10 here