Skip to main content

MVC MiniProj1

Mini Project Discussion:-
-->Sending ResultSet object from DAO class to service is bad practice because
a.)ResultSet object is not Serializable object
b.)To receive ResultSet object in service layer we need to write jdbc code and writing jdbc code in service layer is bad practice
-->To overcome above problems
Solution(1) Use RowSets instead of ResultSets
-->RowSets are serializable objects
-->To receive RowSets we need to place jdbc code in service class
-->Some jdbc drivers do not support RowSets
Solution(2) Copy the records of ResultSet to Collection and send Collection
-->Collections are serializable objects
-->We can receive collection in service class as non jdbc code
-->If you are looking to perform more read operations on collections then use non-synchronized collection for better performance
E.g: ArrayList, HashMap
-->If you are looking to perform both read write operations on collections then use Synchronized collections for Thread safety
E.g: Hashtable, Vector & etc...
(Q) Problem in copying the records of ResultSet to ArrayList collections ?

-->Each element of ArrayList holds only one object, but each record of ResultSet contains multiple values, So we can not copy the each record of ResultSet to the each element of ArrayList
-->To solve this problem copy the records of ResultSet to one object of BO class and add that object(BO) to ArrayList element

Sample Code:
  1. public class StudentBO{
  2.  private int sno;
  3.  private String sname;
  4.  private String sadd;
  5.  //setters & getters
  6.   .....
  7. }
  1. //Logic to copy ResultSet records to ArrayList collections
  2. ResultSet rs=st.executeQuery("select * from student");
  3. List<StudentBO> list= new ArrayList<StudentBO>();
  4. while(rs.next()){
  5. StudentBO bo=new StudentBO();
  6.  //copy each record to BO class object
  7. bo.setSno(rs.getInt(1));
  8. bo.setSname(rs.getString(2));
  9. bo.setSadd(rs.getString(3));
  10. //add BO class objects to ArrayList collections
  11. list.add(bo)
  12. }//while
(Q) Where did you used java bean in your project ?
a.)As helper class to transfer ResultSet records to ArrayList collection
b.)As BO class to holds inputs(form data) or outputs
c.)As DTO class to transfer huge amount of data from one layer to another layer
d.)As BO class representing persistence logic data
e.)To store huge amount of form data in single session/ request / application attribute, it will be placed in java bean class object

(Q) Where did you use collectionin your project ?
-->To send ResultSet object data from one layer to another layer, we copy the data to list collection
-->To maintain JDBC properties in properties file we use java.util properties
-->To develop dynamically growable buffer or cache we use Hashmap
-->To maintain huge amount of data in single session/request/application attribute. We place that huge amount of data in list collection and etc...
Mini Project :-
View
   |-->html files, jsp files
Controller
   |-->Servlet component
Model
   |-->service class(java class)
   |-->DAO class(java class)

a.)Given based on MVC(2) Architecture
b.)Service class, DAO class comes under Model Layer components
c.)ResultSet data copied list collection using BO support
d.)DAO, service class bending results to other layer in the form of ListBO, ListDTO respectively
e.)Ordinary buttons are used to submit the request using javaScript
f.)JavaScript also used for form validations and also for printing webpage
g.)Controller servlet is using rd.forward(-,-) to forward the request to destination webpage
h.)Controller servlet is passing data to result JSP's in the form of request attributes
i.)Facility is given to get printout of webpage and to download output as downloadable file


-->While developing Multi-Layer app we don't catch and handle exceptions in DAO, service class that means we declare the exception to be thrown to its caller layer
-->If we catch and handle exception in DAO, service classes, the raised exception will be eaten and suppressed in those classes itself so we can't propagate the exception to the user for display.

-->To overcome these problem DAO class propagates the exception to service class, service class propagates the exception to controller class and controller class displays the exception in non-technical terms by forwarding control to error page

Comments

Popular posts from this blog

JSP Comments

Comments in JSP:- -->Compiler /Interpreter doesn't take commented code for compilation /Interpretation, so the commented code doesn't participate in execution JSP supports 3 types of comments:- a.)HTML comments /Template text comments/ Output comments Syn :- <!---text---> -->Recognized by html interpreter of browser b.)JSP comments /Hidden comments Syn :- <%--text--%> -->JSP page compiler recognize these comments c.)Java comments /Scripting comments Syn :- //-->For single line /*-- -----*/-->For multiple line -->Java compiler(java) recognize these comments -->In Eclipse IDE JES class for first.jsp comes in our(workspace)folder/.metadata/.plugins/.org eclipse Comments (1)JSP comment<%--%> (2)Java comment(// or /*--*/) (3)HTML comments(<!---> JES Source Code (1)No (2)Yes (3)Yes In JES compiled code (1)No (2)No (3)Yes In the code going to browser (1)No (2)No (3)Yes Output (1)No (2)No (3)No -->Jsp comments are not visible in any phase...

Scripting Tags

JSP Tags/ Elements (1)Scriptlet     Standard syn:-         <%.........%>     xml syn:-        <jsp:scriptlet>...</jsp:scriptlet> Note: All scripting tags allows us to place script code(java code) 1.)The code placed in scriptlet go to _jspService(-,-) of JES class 2.)In a jsp page we can have zero or more scriptlets 3.)We place request processing logics in scriptlets 4.)Variables declared in scriptlets becomes the local variables in _jspService(-,-) of JES class in first.jsp In first.jsp: <% int a=10;  out.println("square:"+(a*a));%> In first_jsp.java(JES): public class first_jsp extends..{     public void _jspService(-,-){        int t=30;        out.println(“Square:”+(t*t));     }  } The code placed in scriptlet can use implicit objects of jsp because implicit objects and the code placed scriptlet goes to _jspService(-...

Project Architecture's

1.) Functional flow/ Architecture a.) Only for 6+/7+years b.) Explain the flow of process/business 2.) Technical Flow/Architecture a.) Upto 5+ years b.) Explain technologies /components that are involved in the project Servlet & JSP Project Architecture:- 1.)What is need of Business Deligate to convert VO class object to DTO class object ? a.) If Business Deligate is not there servlet component directly prepares DTO class object by receiving and translating form data and passes to service class, if service class excepts certain input in other format like numeric employee number as string employee number then we need to modify servlet component code i.e For the changes that happened in business tier service component we have to modify servlet component of presentation tier b.) If Business Deligate is taken then it gets original form data as VO class object having string inputs and converts VO class object to DTO class object to pass to service class c.) If service class excepts ...