Sunday, 26 March 2017

Java Script programs on displaying country's capital

Write an HTML page that contains a selection box with a list of 5 countries. When the user selects a country, its capital should be printed next to the list. Add CSS to customize the properties of the font of the capital (color, bold and font size).  


As we all know Javascript can change HTML content.One of javascript HTML method is getElementById()
This example uses the method to "find" an HTML element (with id="txtSelectedCapital") and changes the element content (innerHTML) to "selectedValue":




dropDown.options[dropDown.selectedIndex].value;
This line allows us to select the drop down list value based on the index and store it in some variable for displaying in the browser.

Sunday, 19 March 2017

USING PREPARED STATEMENT IN JSP

The PreparedStatement interface is a subinterface of Statement. It is used to execute parameterized query.
Improves performance: The performance of the application will be faster if you use PreparedStatement interface because query is compiled only once.

Following is the example implementing the same interface in jsp:

In this jsp execution you are not required to explicitly keep mysqlconnector.jar as it should be present in tomcats lib folder like below:








Create emp_table in mysql as follows:

 This is the output for your jsp:






Friday, 17 March 2017

JSP AGE VALIDATION ALONG WITH CSS


A web application that takes name and age from an HTML page. If the age is less than 18 it should send a page with “Hello <name>, you are not authorized to visit the site “message, where <name> should be replaced with the entered name. Otherwise it should send “Welcome <name> to this site “message.

Below is the folder structure that is to be followed for every tomcat application


The html form nameage consist of the link to stylesheet along with the form details:


This is the jsp code for processing age criteria:

Once you start your application in tomcat automatically the corresponding class and java files are generated in the below folder:


Following are the output screens where in based on the age criteria the user will be prompted with the respective messages:








LIST COOKIES IN JSP ALONG WITH CSS

A web application that lists all cookies stored in a browser 

Today we are going to learn how to style our JSP code for which same folder structure you have to follow like below:


Here the src code for the cookie is as follows:


The CSS style sheet is as follows:


The background image which we are going to use is :


When u start tomcat server and click on the specified project your output will be:






Sunday, 12 March 2017

WTLAB program to implement PASSWORD MISMATCH using servlets


A web application for implementation: The user is first served a login page which takes user’s name and password. After submitting the details the server checks these values against the data from a database and takes following decisions. If name and password matches, serves a welcome page with user’s full name. If name matches and password doesn’t match, then serves “password mismatch “page. 
If name is not found in database serves a registration page where user’s full name is asked and on submitting the details are stored in database

To implement the above program using servlets all u require is :
1.Tomcat container
2.Notepad
3.Browser
4.Connector.jar file which is to be placed in tomcat's lib folder

Initially u have to create a folder structure as follows:

As u can see in the above image the html files are kept outside.It is your choice to keep it in src folder or not.
The login.html file consist of 


 Focus on the action attribute in the above form, the url port number may change based on ur tomcats setting.
The regi.html file consist of 


The WEB-INF directory consists of 


 The classes folder may consist of  all the java files and .class files as follows

The servlet process.java has following set of instructions:

The servlet regi.java has following



Open mysql and create the required database and tables as follows





After writing the java files u have to compile it in cmd prompt


Once compiled move out of classes folder and type web.xml contents

Open Tomcat and type the url of ur project

Initially i assumed no user information is present in the database so u will be redirected to registration page.
After registration u will be asked to login ,These are the details of the registered user in mysql.

Once u specify the password and username u will get successfull response.

If by mistake u forgot and specified wrong password u will get the following message.

This is it.Same logic we can implement in jsp and php as well.U can also use framesets for this program just like i discussed in my previous posts.Do not stick to same program try to use either bootstrap or manual css for enhancing its looks.

Hope this post is useful to all who are watching right now.










Thursday, 2 March 2017

jsp programs of wtlab

Following should be the directory structure that is always followed for implementing jsp applications.

In Tomcat web-apps folder you have to create your own respective folder for jsp implementation.

Sessions implementation using jsp:It requires following three files:
                                                             1.login.jsp
                                                              2.home.jsp
                                                              3.logout.jsp




The output of above program is






 Age validation implementation using jsp:



The output of above program is


Calculator implementation in jsp


The above programs output is as follows: