Skip to main content

PW vs JW

(Q)What is the difference between PrintWriter & JspWriter ?
PrintWriter
-->Doesn't support buffering while writing data to response objects
-->Concrete class of java.io package
-->print(-) methods of these class doesn't throw IOException
-->Useful in servlet programming to get stream object pointing to response object
JspWriter
-->Supports buffering
-->Abstract class of javax.servlet.jsp package
-->throws IOException
-->Useful in JSP programming in directly as the type of "out" implicit object
Note: JspWriter object internally uses PrintWriter if jsp page is taken without buffer(<%@page buffer="none"%>)
8.)isThreadSafe
-->Our servlet, jsp component is not  threadsafe by default because for multiple requests multiple threads will be started on one object of our servlet/JES class objects simultaneously
-->If our servlet/JES class implements javax.servlet.SingleThreadModel(I) the underlying container takes the responsibility of making our servlet component /jsp component as threadsafe by allowing one thread at a time on to our servlet/JES class object
  1. <%@page isThreadSafe="false"%>
-->Makes JES class to implements SingleThreadModel(I)(jsp component becomes thread safe)
  1. <%@page isThreadSafe="true"%>
-->JES class doesn't implements SingleThreadModel(I) (jsp component is not thread safe)
  1. public class TestServlet extends HS implements javax.servlet.SingleThreadModel
  2. {
  3.   ...
  4. }
9.)isELIgnored
-->Writing java code in jsp is a bad practice but we place java code in jsp for arithmetic, logical operations to avoid java code and to perform arithmetic and logical operations without java code use EL(Expression Language)
Syn: $(<expr>)
E.g
  1. $(3+4)
  2. $(3*4)
  3. <%@page isELIgnored="false"%>
  4. -->Recognises the EL
  5. $(3+4)-->gives 7
  6. <%@page isELIgnored="true"%>
  7. -->Ignores the EL
  8. $(3*4)-->gives $(3*4)
10.)errorPage
-->Useful to configure error page for jsp component
-->Errorpage: The page that executes when exception is raised in jsp
  1. <%@page errorPage="err.jsp"%>
11.)isErrorPage
-->Makes ordinary jsp pages as error page. Useful to display exception related messages as the non technical guiding messages. The implicit object "exception" will be created in the error page
  1. <%@page isErrorPage="true"%>
Attributes
info
import
contentType
extends
session
buffer
autoFlush
isELIgnored
isErrorPage
isThreadSafe
errorPage
Default value
....
....
text/html
Container supplied class
True
8kb
True
False
False
True
....
Important points on <@page> tag
1.)Tag & attributes are case sensitive
2.)Invalid attributes are not allowed
3.)Except "import" attribute no other attribute is allowed to repeat for multiple times with different values
4.)Except "import" attribute no other attribute can have multiple values separated with "," symbols

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 ...