Wednesday, November 26, 2014

Define Error page in Java web App



Page which will display the Error detail : ErrorPage.jsp

<%@ page isErrorPage=”true” %>
<html>
<body>
<strong>I am Error Page.</strong><br>
Error is : ${pageContext.exception}<br>
</body>
</html>

Page which will cause Error : Hello.jsp

<%@ page errorPage=”ErrorPage.jsp” %>
<html>
<body>
<%=1/0%>
</body>
</html>

Web.xml

<error-page>
          <error-code>404</error-code>
           <location>/jsp/ErrorPage.jsp</location>
</error-page>

<error-page>
          <error-code>java.lang.ArithMeticException</error-code>
           <location>/jsp/ErrorPage.jsp</location>
</error-page>

How to define Error Page in web.xml


Exception Based

<error-page>
<exception-type>java.lang.ArithmeticException</exception-type>
<location>/ExceptionError.jsp</location>
</error-page>

HTTP status code based 

<error-page>
<error-code>404</error-code>
<location>/NotFound.jsp</location>
</error-page>

Friday, November 21, 2014

RADIUS protocol's one line Question/Answer

RADIUS : Remote Authentication Dial In User Service

RADIUS RFC'S : 2865, 2866

0)  Radius is Stateless protocol, Extensible protocol

1) Radius supports protocol for Authentication are : PAP,CHAP,PPP,UNIX-LOGIN

2) Radius Authentication port : 1812

3) Radius Accounting Port : 1813

4) Radius uses UDP

5) Radius Packet Format

6) Code : 1 Octet,   Identifier : 1 Octet,  Length : 2 Octet, Authenticator : 16 Octet

7) Length : Min 20 and Max 4096

8) Radius Attributes
   
CodeAttributes
1User-Name
2User-Password
3CHAP-Password
4NAS-IP-Address
5NAS-Port
6Service-Type
7Framed-Protocol
8Framed-IP-Address
9Framed-IP-Netmask
10Framed-Routing
11Filter-Id
12Framed-MTU
13Framed-Compression
14Login-IP-Host
15Login-Service
16Login-TCP-Port
17(unassigned)
18Reply-Message
19Callback-Number
20Callback-Id
21(unassigned)
22Framed-Route
CodeAttributes
23Framed-IPX-Network
24State
25Class
26Vendor-Specific
27Session-Timeout
28Idle-Timeout
29Termination-Action
30Called-Station-Id
31Calling-Station-Id
32NAS-Identifier
33Proxy-State
34Login-LAT-Service
35Login-LAT-Node 3
36Login-LAT-Group
37Framed-AppleTalk-Link
38Framed-AppleTalk-Network
39Framed-AppleTalk-Zone
40-59(reserved for accounting)
60CHAP-Challenge
61NAS-Port-Type
62Port-Limit
63Login-LAT-Port

9) Diameter Protocol is double than Radius

10) Diameter works on TCP or SCTP protocol

11) Diameter uses Transport level security IPSEC , TLS




Wednesday, November 19, 2014

Include directive vs jsp:include action


Include directive

include directive should be use to include the static contents
which is not getting changed frequently.

It includes the content at the translation time

example
<%@include file="/jsp/core/includes/common/Footer.jsp" %>

<jsp:include> action tag

include action tag is used to include the content which is getting changeg frequently

it includes the content at the runtime

example
<jsp:include page="/jsp/data/dynamic.jsp"/>

Tuesday, November 18, 2014

HTTP Status code Range


1) 100 to 199 (Informational)

This range include the Informational codes about the kind of action client should use or respond

2) 200 to 299 (Request success)

This range include the success codes that indicates the success of the request

3) 300 to 399 (Request File is moved)

This range include the code to indicate that the particular document/file location is moved to another location

4) 400 to 499 (Client side Error)

This range codes indicates the error generated by the client side

5) 500 to 599 (Server side Error)

This range codes indicates the error generated by the server side

How to use

To set the status code one should  use the predefined constants for the respective status code using the method :  response.setStatus(response.SC_ABC_XYZ);


Status Code
Purpose
100-199
Informational
200-299
Request was successful
300-399
Request file has moved.
400-499
Client error
 500-599
Server error.



Some Status Code with their Short Meaning

100 : Continue

200 : OK
202 : Accepted
204 : No Content
205 : Reset Content

301 : Moved Permanentely
302 : Found
303 : See Other
304 : Not Modified


400 : Bad Request
: Bad syntax of the request

401 : Unauthorized
: client tries to access the password protected resource, 

403 : Forbidden
: server refuse to supply the requested resource

404 : Not Found
: when the requested resource is not found on the server.

405 : Method Not Allowed
: put,trace,delete,options if server doesnt support the method requested.

415 : Unsupported Media Type
: request contain the document that the server doesnt know how to handle.

417 : Expectation Failed
: request ask to process some document with 100 code in header, in this request response
 server can respond with code 417


500 : Internal Server Error
: When Server is Confused.

501 : Not Implemented
: doesnt support the functionality to fullfill the request.

503 : Service Unavailable
: When server is not able to fullfill the request service. because of overloading or maintenance or etc




How to Include Header and Footer in all Jsp files Dynamically


Include following tag in your web.xml file with your files proper path
it will include Header.jsp in header of all jsp file and Footer.jsp in footer of all the jsp files

<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<include-prelude>/view/commons/Header.jsp</include-prelude>
<include-coda>/view/commons/Footer.jsp</include-coda>
</jsp-property-group>
</jsp-config>

Sunday, November 16, 2014

STRUTS2 Wildcard Congiguration in struts.xml file

Wildcard configuration in struts.xml file

<action name="*/*"  class="com.raj.rk.controller.{1}.{1}CTRL" method="{2}" >                                     
            <result name="create">/view/{1}/{1}Create.jsp</result>
            <result name="update">/view/{1}/{1}Update.jsp</result>                       
            <result name="view">/view/{1}/{1}View.jsp</result>
            <result name="list">/view/{1}/{1}Search.jsp</result>
</action>

Explanation

name = */*  
If the request comes for action policy/create.action, then the {1} will be policy and {2} will be create. so this both values will be mapped into the respected position in the action tag. and it will work accordingly.

Controller
In this policy/create call the controller called will be PolicyCTRL.java
and the method called will be create() inside the the PolicyCTRL.java class

Result
and the result file called will be /view/policy/PolicyCreate.jsp

Friday, November 7, 2014

FILTER vs INTERCEPTOR

FILTERS
0)  Filter is an Interface
1)  Filters are Java Components. somewhat equivalent to servlet.
2)  Filters intercepts and process the request before it sent to the actual servlet.
- on request object filter can do security checks
- filter can do some log work
- filter can change the request parameter
- filter can reformat the request headers 
- filter can take some decision based on request parameters
3)  Filter intercepts the response received from the servlet before it sent to the end user.
- filter can do some log work for the response
- filter can change the response stream

4)  Filters are configurable in DD (Deployement Descriptor)
5)  Container decides when to invoke which filter
6)  Filters have init(), destroy() and doFilter() methods
7)  One request can be intercepted by multiple filters
8)  Every filter must implemens the Filter Interface
9)  Filter interface is in package "import javax.servlet.Filter;"
10) doFilter(ServletRequest request, ServletResponse response, FilterChain fchain) 
11) As per the declaration of filter in the DD the filter chain will be prepared for the similar url-mapping and servlet-names.
12) The Filter chain concept can also be called a filter stack.

INTERCEPTORS
0)  Interceptor is an Interface
1)  Interceptors are struts2 components similar to Filter
2)  Interceptors intercepts the request before it reach to the servlet and can do the same      
     work as filter can do.
3)  Interceptors intercepts the respons before it reach to the end user and can perform the 
     same work as filter can do.
4)  Interceptors can be declared in the struts specific configuration file (struts.xml)
5)  Interceptors are can be called action specific
6)  Programmer can be define in specific order to create stack of the interceptor. (as filter 
    chaining )
7)  Prepared stack can be used at multiple times for the specified actions
8)  Struts2 provides many useful interceptors (i.e 
     http://struts.apache.org/release/2.3.x/docs/interceptors.html)
9)  To create interceptor we need to implement Interceptor interface
10) Interceptor have three methods void init(),  void destroy() and Strinng 
      intercept(ActionInvocation acIn)
11) package : "import com.opensymphony.xwork2.interceptor.Interceptor;"
12) Interceptor can exclude and include specific method's execution.

I think this is enough basic information about FILTER and INTERCEPTOR :)

KEEP VISITING :) GIVE YOUR RATING AND COMMENTS

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...