Advanced Enterprise JAVA LAB PDF

Title Advanced Enterprise JAVA LAB
Author Cheran R
Course M.sc(Computer Science)
Institution Thiruvalluvar University
Pages 87
File Size 3.4 MB
File Type PDF
Total Downloads 17
Total Views 89

Summary

GOVERNMENT ARTS COLLEGECHIDAMBARAM-608 102Re-Accredited by NAAC with ‘B’ Grade (Affiliated to Thiruvalluvar University, Vellore)PG DEPARTMENT OF COMPUTER SCIENCECBCS PATTERN – [2020-2021]ADVANCED ENTERPIRSE JAVAPROGRAMMING LABTHIRUVALLUVAR UNIVERSITYAVAILABLE STUDY METRIAL HERECBCS PATTERN 2020 – 20...


Description

GOVERNMENT ARTS COLLEGE CHIDAMBARAM-608 102 Re-Accredited by NAAC with ‘B’ Grade (Affiliated to Thiruvalluvar University, Vellore)

ADVANCED ENTERPIRSE JAVA PROGRAMMING LAB

PG DEPARTMENT OF COMPUTER SCIENCE CBCS PATTERN – [2020-2021]

THIRUVALLUVAR UNIVERSITY AVAILABLE STUDY METRIAL HERE

CBCS PATTERN 2020 – 2021: UG:  Programming in C  C++ and data structure PG: 1ST YEAR:  Enterprise java programming lab manual  Programming using C#.NET lab manual  Design and analysis of algorithm lab manual  Web Application using C#.NET lab manual

 Advanced Enterprises Java Programming lab manual

CBCS PATTERN 2017 – 2018: UG: 1ST YEAR:      

Programming in C Allied Mathematics - 1 C Lab manual C++ and data Structure Allied Mathematics - 2 C++ & data structure Lab Manual

2ND YEAR:    

Java Programming Design and analysis of algorithms Computer organization and architecture Database management system lab manual

3RD YEAR:

          

Mobile application development Data communication and network Data Mining Software Engineering Mobile Application Development Lab Manual Operating System Lab Manual Cloud Computing Open Source Programming ASP.NET OSP Lab Manual ASP.NET Lab Manual

PG: 1ST YEAR:         

Formal Language and Automata Theory Cloud Computing Compiler Design DBMS Lab Manual Advanced Java Programming Lab Manual Web Application Using C# Lab Manual UNIX Programming Lab Manual Enterprise Java Programming Lab Manual Enterprise Application Using C# Lab Manual

2ND YEAR:    

Design and analysis of algorithms Mobile Computing Mobile Computing Lab Manual Design and analysis of algorithms Lab Manual

NOTE: U need any study materials contact me… R.CHERAN M.Sc [Computer Science] Contact: 9952622921 Email: [email protected]

SYLLABUS

1. JSP and MVC with Request Dispatcher. 2. JSF in JSP Pages, Using all HTML and core render kit. 3. Actions and Forms. 4. Properties and Messages. 5. Creating Web Client and Session Bean. 6. Bean Managed Transactions and Container Managed Transaction. 7. Object Relation Mapping and Collection Mapping. 8. Association Mapping and Component Mapping. 9. Inheritance Mapping. 10. Spring Actions and Spring MVC.

1. JSP AND MVC WITH REQUEST DISPATCHER AIM: Develop a JSP and MVC with request dispatcher. PROCEDURE: STEP 1: Open a new java web Application on Netbeans Editor. STEP 2: Open a new Web Application project Type project nameselect server finish. STEP 3: then add a new JSP page and name for index.jsp. STEP 4: Add then next two servlet page and name for loginpage.java and welcomeuser.java. STEP 5: Run the Index page and verify the Result in servlet page. STEP 6: save the project (ctrl+s). STEP 7: Run the project (F5).

R CHERAN M.Sc [Computer Science]

Page 1

PROGRAM: Index.jsp





Servlet Request Dispatcher

Username:

Password:





R CHERAN M.Sc [Computer Science]

Page 2

Loginpage.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class loginPage extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/jsp"); PrintWriter pwriter = response.getWriter(); String name=request.getParameter("uname"); String pass=request.getParameter("upass"); if(name.equals("cs") && pass.equals("cs97")) { RequestDispatcher dis=request.getRequestDispatcher("WelcomeUser"); dis.forward(request, response); } else { pwriter.print("User name or password is incorrect!"); RequestDispatcher dis=request.getRequestDispatcher("index.jsp"); dis.include(request, response); } } } Welcomeuser.java import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; R CHERAN M.Sc [Computer Science]

Page 3

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class WelcomeUser extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter pwriter = response.getWriter(); String name=request.getParameter("uname"); pwriter.write(""); pwriter.write("Servlet Request Dispatcher"); pwriter.write("Congratulations! " + name + ", You are an authorised login!"); pwriter.write(""); pwriter.close(); } }

R CHERAN M.Sc [Computer Science]

Page 4

OUTPUT:

R CHERAN M.Sc [Computer Science]

Page 5

2. JSF IN JSP USING CORE RENDER KIT AIM: Develop a java server page Application using JSF in JSP. PROCEDURE: STEP 1: Open a new java web Application on Netbeans Editor. STEP 2: Open a new Web Application project Type project nameselect serverand last one select a Java Server Faces (JSF) Framework finish. STEP 3: then add a new JSP page for giving input data such as name, Father name, dob, medium, place. STEP 4: Add then next one JSP page for registering these values and display it. STEP 5: save the project (ctrl+s). STEP 6: Run the project (F5).

R CHERAN M.Sc [Computer Science]

Page 6

PROGRAM: Register.jsp





JSP Page





R CHERAN M.Sc [Computer Science]

Page 7







Result.jsp

R CHERAN M.Sc [Computer Science]

Page 8





JSP Page



R CHERAN M.Sc [Computer Science]

Page 9







R CHERAN M.Sc [Computer Science]

Page 10

OUTPUT:

R CHERAN M.Sc [Computer Science]

Page 11

3. ACTION AND FORMS AIM: Develop a Web application using Struts Action and forms. PROCEDURE: STEP 1: Open a new java web Application on Netbeans Editor. STEP 2: Open NetBeans IDE, choose File New Project. STEP 3: New open a new project and choose a web Application. STEP 4: Add a coding on coding windows using getter setter method. STEP 5: Run the index page and it forward to proper page it is Success or Failure. STEP 6: save the project (ctrl+s). STEP 7: Run the project (F5).

R CHERAN M.Sc [Computer Science]

Page 12

PROGRAM: Index.jsp



Login Example

username:

password:

R CHERAN M.Sc [Computer Science]

Page 13

 





Failure.jsp



JSP Page

check your username&password

R CHERAN M.Sc [Computer Science]

Page 14

Success.jsp



JSP Page

login successfully..!!!

IndexActionForm.java package com.myapp.struts; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; public class IndexActionForm extends org.apache.struts.action.ActionForm { public String getUser() { return user; } public void setUser(String user) { this.user = user; }

R CHERAN M.Sc [Computer Science]

Page 15

public String getPass() { return pass; } public void setPass(String pass) { this.pass = pass; } private String user; private String pass; public IndexActionForm() { super(); } public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if((getUser()==null) || (getUser().trim().equalsIgnoreCase(""))) { errors.add("usererror", new ActionMessage("error.username.required")); } if((getPass()==null) || (getPass().trim().equalsIgnoreCase(""))) { errors.add("passerror", new ActionMessage("error.passname.required")); } return errors; } @Override public void reset(ActionMapping mapping,HttpServletRequest request) { setPass(""); setUser(""); super.reset(mapping,request); } } IndexStrutsAction.java package com.myapp.struts; R CHERAN M.Sc [Computer Science]

Page 16

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class IndexStrutsAction extends org.apache.struts.action.Action { /* forward name="success" path="" */ private static final String SUCCESS = "success"; private static final String FAILURE = "failure"; @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession hs=request.getSession(true); IndexActionForm obj=(IndexActionForm)form; hs.setAttribute("Session", obj.getUser()); if(obj.getPass().equalsIgnoreCase(obj.getUser())) { return mapping.findForward(SUCCESS); } else { return mapping.findForward(FAILURE); } } }

R CHERAN M.Sc [Computer Science]

Page 17

OUTPUT:

R CHERAN M.Sc [Computer Science]

Page 18

4. PROPERTIES AND MESSAGES AIM: Develop a Web application for Struts Properties and Messages. PROCEDURE: STEP 1: Open a new java web Application on Netbeans Editor. STEP 2: Open NetBeans IDE, choose File New Project. STEP 3: New open a new project and choose a web Application. STEP 4: Add a coding on coding windows using getter setter method. STEP 5: Run the Index page and verify the Result page. STEP 6: save the project (ctrl+s). STEP 7: Run the project (F5).

R CHERAN M.Sc [Computer Science]

Page 19

PROGRAM: Index.jsp





Provide Address Information

Provide address information bellow form: * marked fields are required



Name:* Street: City:* Country: pin:*



Result.jsp





R CHERAN M.Sc [Computer Science]

Page 20

JSP Page

register done Name:. Street:. City:. Country:. Pin:.

appActionForm.java package com.myapp.struts; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; public class appActionForm extends org.apache.struts.action.ActionForm { private String name; private String street; private String city; private String country; private int pin; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getStreet() { return street; } public void setStreet(String street) { this.street = street; R CHERAN M.Sc [Computer Science]

Page 21

} public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } public int getPin() { return pin; } public void setPin(int pin) { this.pin = pin; } public appActionForm() { super(); } public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if(this.name==null || this.name.trim().equals("")) errors.add("name",new ActionMessage("error.name.required","Name")); if(this.city==null || this.city.trim().equals("")) errors.add("city",new ActionMessage("error.city.required","City")); if(this.pin==0) errors.add("pin",new ActionMessage("error.pin.required","Pin")); return errors; } } appStrutsAction.java package com.myapp.struts; R CHERAN M.Sc [Computer Science]

Page 22

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class appStrutsAction extends org.apache.struts.action.Action { /* forward name="success" path="" */ private static final String SUCCESS = "success"; @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward(SUCCESS); } } ApplicationResource.Properties #--added-error.name.required= name required error.city.required= city required error.pin.required= pin required

R CHERAN M.Sc [Computer Science]

Page 23

OUTPUT:

R CHERAN M.Sc [Computer Science]

Page 24

5. (A) WEB CLIENT AIM: Develop a Web application to create a web client in Enterprise beans. PROCEDURE: STEP 1: Open a new java web Application on Netbeans Editor. STEP 2: Open NetBeans IDE, choose File New Project. STEP 3: Java EE category select EJB Module  Then click NextTtype nameselect serverfinish. STEP 4: Add a session bean and write code for Add Method STEP 5: Run the Session Bean [Create JAR File] STEP 6: New open a new project and choose a web Application. STEP 7: Then Add a JAR File in Library. STEP 8: Run the index page and verify the output on servlet page. STEP 9: save the project (ctrl+s). STEP 10: Run the project (F5).

R CHERAN M.Sc [Computer Science]

Page 25

PROGRAM: Index.jsp



JSP Page

Book Management

Enter The book Name OR



Result.java package cheran; import com.cheran.stateless.NewSessionBeanLocal; import java.io.IOException; import java.util.List; R CHERAN M.Sc [Computer Science]

Page 26

import javax.ejb.EJB; 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; @WebServlet(name = "result", urlPatterns = {"/result"}) public class result extends HttpServlet { @EJB private NewSessionBeanLocal NewSessionBean; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String bookName=request.getParameter("book"); out.println(""); out.println(""); if(bookName!=null) { NewSessionBean.addBook(bookName); out.println("Book Added Successfull"); } ListbooksList=NewSessionBean.getBooks(); R CHERAN M.Sc [Computer Science]

Page 27

out.println("Book List"); for(int i=0;i R CHERAN M.Sc [Computer Science]

Page 44

newservlet.java package msc; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.HashSet; import java.util.Set; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class NewServlet extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String name=request.getParameter("name"); String itemid1=request.getParameter("itemid1"); String itemid2=request.getParameter("itemid2"); R CHERAN M.Sc [Computer Science]

Page 45

int quant1=Integer.parseInt(request.getParameter("quantity1")); int quant2=Integer.parseInt(request.getParameter("quantity2")); int amt1=Integer.parseInt(request.getParameter("amt1")); int amt2=Integer.parseInt(request.getParameter("amt2")); Cart cart = new Cart(); Cart.setName(name); Items item1 = new Items(cart,itemid1, amt1, quant1); Items item2 = new Items(cart,itemid2, amt2, quant2); Set itemsSet = new HashSet(); itemsSet.add(item1); itemsSet.add(item2); Cart.setItemses(itemsSet); Cart.setTotal(amt1*quant1 + amt2* quant2); SessionFactory sessionFactory = null; Session session = null; Transaction tx = null; //Get Session SessionFactory sf=new Configuration().configure().buildSessionFactory(); Session s=sf.openSession(); Transaction tr=s.beginTransaction(); //sessionFactory = HibernateUtil.getSessionFactory(); //session = sessionFactory.getCurrentSession(); System.out.println("Session created"); //start transaction R CHERAN M.Sc [Computer Science]

Page 46

//tr = session.beginTransaction(); //Save the Model objects s.save(cart); s.save(item1); s.save(item2); //Commit transaction tr.commit(); //System.out.println("Cart ID="+cart.getCartId()); try (PrintWriter out = response.getWriter()) { out.println(""); out.println(""); out.println(""); out.println("Servlet NewServlet"); out.println(""); out.println(""); out.println("Cart ID="+cart.getCartId() + " Added"); out.println(""); out.println(""); } } Enter password: **** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 R CHERAN M.Sc [Computer Science]

Page 47

Server version: 5.1.30-community MySQL Community Server (GPL)

mysql> create database collect; Query OK, 1 row affected (0.47 sec)

mysql> use collect; Database changed

mysql> CREATE TABLE `Cart` ( -> `cart_id` int(11) unsigned NOT NULL AUTO_INCREMENT, -> `total` decimal(10,0) NOT NULL, -> `name` varchar(10) DEFAULT NULL, -> PRIMARY KEY (`cart_id`) -> ) AUTO_INCREMENT=1; Query OK, 0 rows affected (0.65 sec)

mysql> desc cart; +---------+------------------+------+-----+---------+----------------+ | Field | Type

| Null | Key | Default | Extra

|

+---------+------------------+------+-----+---------+----------------+ | cart_id | int(11) unsigned | NO | PRI | NULL | auto_increment | R CHERAN M.Sc [Computer Science]

Page 48

| total | decimal(10,0) | NO | | name | varchar(10)

| NULL

| YES |

| NULL

|

| |

|

+---------+------------------+------+-----+---------+----------------+ 3 rows in set (0.19 sec)

mysql> CREATE TABLE `Items` ( -> `id` int(11) unsigned NOT NULL AUTO_INCREMENT, -> `cart_id` int(11) unsigned NOT NULL, -> `item_id` varchar(10) NOT NULL, -> `item_total` decimal(10,0) NOT NULL, -> `quantity` int(3) NOT NULL, -> PRIMARY KEY (`id`), -> KEY `cart_id` (`cart_id`), -> CONSTRAINT `item_key` FOREIGN KEY (`cart_id`) REFERENCES `Cart` (`cart_ id`) -> ) AUTO_INCREMENT=1 ; Query OK, 0 rows affected (0.22 sec) mysql> desc Items; +------------+------------------+------+-----+---------+----------------+ | Field

| Type

| Null | Key | Default | Extra

|

+------------+------------------+------+-----+---------+----------------+ | id

| int(11) unsigned | NO | PRI | NULL | auto_increment |

R CHERAN M.Sc [Computer Science]

Page 49

| cart_id | int(11) unsigned | NO | MUL | NULL | | item_id | varchar(10)

| NO |

| item_total | decimal(10,0) | quantity | int(3)

| NULL |

| NO |

| NO |

| |

| NULL |

| NULL

|

| |

+------------+------------------+------+-----+---------+----------------+ 5 rows in set (0.07 sec)

mysql> select * from cart; +---------+-------+------+ | cart_id | total | name | +---------+-------+------+ |

1 | 59 | cheran |

|


Similar Free PDFs