Skip to main content

Posts

Showing posts from 2013

Free Java Video tutorials -java EE JSP Servlet Maven Spring Hibernate

First of all “ HAPPY NEWYEAR TO ALLZ… ” . I have been thinking of how can I start this new year; with do something good to people ; and I end up with writing something in this blog which helps to java newbies . I am going to share some open source(free) resource helps you to get started with java web development . Java video tutorials 1.    http://javabrains.koushik.org/p/home.html 2.    http://www.youtube.com/user/patrickwashingtondc 3.    http://www.youtube.com/channel/UCJiNQzZSUO6kYlbb4WUvJQA 4.    http://java9s.com/ 5.    http://www.pvtuts.com/java/java-introduction 6.    http://www.javavids.com/ 7.    http://www.ittrainersonline.com/maven-online-training-videos/ 8.    http://www.youtube.com/user/javascreencasts/about Paid tutorials : 1.http://www.vtc.com/products/Advanced-Java-Programming-Java-SE7-Tutorials.htm 2. http://www.lynda.com/Java-training-tutorials/1077-0.html don't worry  about the money you spend ;those are really wroth than your money .I

How to connect pgAdmin to heroku postgresql

1.first of all you need to go to https://postgres.heroku.com/databases and click on the database you want to connect with. 2.And copy the host, database, name ,user,port,password . 3.Now open pgAdminIII client and click on add connection to servers button and paste the credential copied from the heroku ;  maintenance DB referrers to database name. 4. Then in the "Advanced" tab you must enter the maintenance DB name(Database name) surrounded with a single quotes.   eg: 'dbname' 5.After that click on "ok" button done....!!!! for further reference go to following links : Connect to a heroku database with pgadmin heroku postgresql How to hide databases that i am not allowed to access

JSP page directives

A jsp page directive looks like this: <%@ directive attribute="value" %> I am not gonna explain each and every page directives here . I would like to discuss about two page directives  which is import and include. First of all consider the import directive . The following simple program illustrate the use of import page directive: The output would be something looks like this: <%@ page language="java" contentType="text/html; charset=UTF-8"     pageEncoding="UTF-8"%>  <%@ page import="java.util.Date" %>   //page directive <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Jsp Basics</title> </head> <body> <%=new Date() %> </body> </html> Tue Nov 12 17:42:34 I

JSP Basic syntax -Declarations Scriptlets

In this post I would like to explain basic syntax of JSP Lets start with the Scriptlet Following is the syntax of scriptlet: <% code goes here…..%> On other hand code rendered inside <% %> these tags considered as jsp code; and compiled as JSP code We have XML equivalent of the above syntax ;it would be looks something like this: Code goes here…… Now let’s write a simple jsp file: <% int i=2; int k=3; int j=k+i; out.println("sum of i and j is:"+j); %> The output would be something like this: Sum of I and j is:5  Nothing special in it; now consider the xml syntax we can run the above code like this: int i=2; int k=3; int j=k+i; out.println("sum of i and j is:"+j); In jsp there is a shortcut for out.println() method .consider the following example <% int i=2; int k=3; int j=k+i; %> Sum of I an j is:<%=k%> Ie <%= variable %> this way we can print a variable inside a jsp file. When compared to out.p

Introduction to JSP

  Now lets explore JSP (Java Server Page) Inoder to understand JSP we have very much understanding of what serverlet is. If you don't have the basic understanding what servlet does . i would recommend review the previous post first and start with this one.So what is a Jsp ?. Before we explore JSP i would like to explain one potential problem of using servlets; to be honest we can develop any web application using servlets we have all required technology to do that so you can capture any user request through url and assign a servlet to handle it and any html code written in servlet .But Creating html code inside servlet is very crucial process means using print writer manipulating a dynamic html page is highly Challenging. We can tackle this situation by using Jsp so that we can write java code inside html code.     

Servlet Context Basics

Context variable can access thorough the entire application. Shared across servlets and users .But session object can't be shared across the user . so it the is an advantage of the context variable  over session. Now lets consider how context can be created and use the same across the entire application: package servlets.first; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; /**  * Servlet implementation class SessionTest  */ @WebServlet(description = "Write data to session and read data from session and from context as well", urlPatterns = { "/SessionTest" }) public class SessionTest extends HttpServlet {     private static final long se

Session creation Using servlet

Using Java Servlet session variable is a mechanism to store user’s data in server. And sessions will last till we are on the site, it will be destroyed when the user quit the site. One main example of session usage is login information. When a user login to a site with his user name and password, sessions will be created for that user in server. By using these session variables servers  programs identify each user Now let's consider about how to write data in to session and read data from the session: package servlets.first; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; /**  * Servlet implementation class SessionTest  */ @WebServlet(description = "Write data to session and read data from sessi

Servlet program to read POST Data

Servlet program to read POST Data in order to pass a post parameter we need a html form consider the following html page: <pre class="prettyprint" > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Post parameter </title> </head> <body> <b>Servlet Post</b> <form method="post" action="PostTest">     //Her the action redirect to the servlet path <input type="text" name="uname" /> <input type="submit" value="Enter" > </form> </body> </html> < /pre > Servlet code would be looks like this: package servlets.first; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpS

Servlet program to read get request or URL data

Servlet program to read get request or URL data Here i am not writing all the code from scratch instead i just provide you the doGet method only.      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        String uname;        response.setContentType("text/html");        PrintWriter out= response.getWriter();        uname= request.getParameter("Uname");                      out.println("<B>Uname:" +uname +"</B>");              }

A simple servlet program that print hello World

Servlet Simple code for Hello World // Import required java libraries import java . io .*; import javax . servlet .*; import javax . servlet . http .*; // Extend HttpServlet class public class HelloWorld extends HttpServlet { private String message ; public void init () throws ServletException { // Do required initialization message = "Hello World" ; } public void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { // Set response content type response . setContentType ( "text/html" ); // Actual logic goes here. PrintWriter out = response . getWriter (); out . println ( "<h1>" + message + "</h1>" ); } public void destroy () { // do nothing. } }

Servlet Life Cycle

Servlet Life Cycle  The Servlet Life cycle can be defined as the entire process from it's creation till the destruction. The following are the are the path followed by the servlets -> The servlet is initialized by calling the init() method . -> The servlet called service method to handle client request -> Then the servlet terminated by calling destroy() method -> Finally servlet is garbage collected by the garbage collector of the JVM Now let's consider the servlet life cycle  in detail INIT() Method The init() method designed to called only once. It is called when the servlet is created and not called over and over and again when the user is requested for the same servlet. The init() method definition looks like this: public void init() Throws ServletException{  // write the initialization code here } The Service method The service method is the main method which helps to perform the actual task . The servlet container call the s

Introduction to Java Servlets

In order to understand the advantages of servlets , you must have the basic under standing of how web browser and web servers are cooperate to provide content to the client . For sake of argument , consider a request for a static web page. The user enters a Uniform Resource Locator( URL) . Then the browser generate a HTTP request for the appropriate server ; the server redirect to the request to the index file of the specified web site . That file return a HTTP response to the client .HTTP header in the HTTP response indicates that the content type of the response. Multipurpose Internet Mail Extension(MIME) is used to the same purpose. for example HTML(Hypertext Markup language ) have a mime type of text/html        In the early days of web, the web server construct a dynamic web page by creating separate process to handle simultaneous request from the client .the process need to open one or more connection to the database to obtain the necessary information. It is communicate wit

JDBC Driver types

Application that use JDBC require JDBC drivers. JDBC drivers are software libraries that communicate between a java application and a database. All JDBC drivers follow the API defined in java SE .                                                          There are four type of drivers available distinguished by their architecture they are: Type 1: JDBC-ODBC Bridge This is an old type when the jdbc is started  ODBC is the dominant  model to communicate with the data base. And java first communicate with database through ODBC. -communicates through ODBC drivers installed on client Can talk to any database But -not  100% Java and not portable -drivers must be on the same computer as application -the ODBC driver must match the database version Type 2:native API/partly Java Communicates through OS specific Api Better performance than JDBC/ODBC Bridge But -not  100% Java and not portable -native API driver must be

What is JDBC and History of JDBC

What is JDBC? JDBC is a java-based API for connecting to relational databases such as mysql , sql,sql server ,postgresql and many others. JDBC stands for “Java Database Connectivity ”. JDBC introduced in 1997 as a part of JDK 1.1 and it been a part of all release of java SE since 1997.   History of JDBC Who uses JDBC? Common uses: -web-based applications hosted by java Enterprise Edition(JEE) servers -Desktop applications working with local and remote databases. Not-so common uses: -Android application  -calls to web service middleware are more common  Alternative to JDBC -Higher level abstraction(usually part of larger application frameworks)   -Spring JdbcTemplate  -RIFE Data mapping APIs -           Hibernate: the most popular object-relational mapping (ORM) API -           I batis: Apache project for mapping SQL results to Java objects -           Java Persistence API(JPA): Part of the java