Your Ad Here

Thursday, January 7, 2010

struts flow

Struts is a open source implementation of MVC design pattern to develop large scale web applications.Struts framework makes it easier to design realible,scalable web applications in java.Struts is not only thread safe but also thread dependent.It instantiates each action once and allows others to be threaded through the original object.Struts reduces the for redundant jsp's.ActionForm stratagy reduces the need of sub class hierarchy.

Struts is a light weight package.It consists of 5 core packages and 5 tag lig directories.


whenever client send request first it goes to CONTROLLER part(ActionServlet)it reads the request data& decides about which action should be performed to process the client request after that it forwards to the appropriate action class(MODEL part)where the functionality code(bussiness logic) will be there, from this MODEL part the control goes back to CONTROLLER part from here the appropriate jsp pages(VIEW part) can be picked up for presenthing(displaying) the result on the clients browser.

Wednesday, December 23, 2009

Invoke a JSP error page from a servlet

You can invoke the JSP error page and pass the exception object to it from within a

servlet. The trick is to create a request dispatcher for the JSP error page, and pass the

exception object as a javax.servlet.jsp.jspException request attribute. However, note that

you can do this from only within controller servlets.
If your servlet opens an OutputStream or PrintWriter, the JSP engine will throw the

following translation error:
java.lang.IllegalStateException: Cannot forward as OutputStream or Writer has already been

obtained
The following code snippet demonstrates the invocation of a JSP error page from within a

controller servlet:
protected void sendErrorRedirect(HttpServletRequest request,
HttpServletResponse response, String errorPageURL, Throwable e) throws
ServletException, IOException {
request.setAttribute ("javax.servlet.jsp.jspException", e);
getServletConfig().getServletContext().
getRequestDispatcher(errorPageURL).forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
{
try {
// do something
} catch (Exception ex) {
try {
sendErrorRedirect(request,response,"/jsp/MyErrorPage.jsp",ex);
} catch (Exception e) {
e.printStackTrace();
}
}
}

Wednesday, November 25, 2009

What is the purpose of tiles-def.xml file, resourcebundle.properties file, validation.xml file?

1. tiles-def.xml

tiles-def.xml is used as a configuration file for an appliction during tiles development
You can define the layout / header / footer / body content for your View.

Eg:

<tiles-definitions>
<definition name="siteLayoutDef" path="/layout/thbiSiteLayout.jsp">
<put name="title" value="Title of the page" />
<put name="header" value="/include/thbiheader.jsp" />
<put name="footer" value="/include/thbifooter.jsp" />
<put name="content" type="string">
Content goes here
</put>
</definition>
</tiles-definitions>

<tiles-definitions>
<definition name="userlogin" extends="siteLayoutDef">
<put name="content" value="/dir/login.jsp" />
</definition>
</tiles-definitions>

2. validation.xml

The validation.xml file is used to declare sets of validations that should be applied to Form Beans.

Each Form Bean you want to validate has its own definition in this file
Inside that definition, you specify the validations you want to apply to the Form Bean's fields.

Eg:

<form-validation>
<formset>
<form name="logonForm">
<field property="username"
depends="required">
<arg0 key=" prompt.username"/>
</field>
<field property="password"
depends="required">
<arg0 key="prompt.password"/>
</field>
</form>
</formset>
</form-validation>

3. Resourcebundle.properties

Instead of having hard-coded error messages in the framework, Struts Validator allows you to specify a key to a message in the ApplicationResources.properties (or resourcebundle.properties) file that should be returned if a validation fails.

Eg:

In ApplicationResources.properties

errors.registrationForm.name={0} Is an invalid name.

In the registrationForm.jsp

<html:messages id="messages" property="name">
<font color="red">
<bean:write name="messages" />
</html:messages>

Output(in red color) : abc Is an invalid name

Saturday, November 7, 2009

Explain Type Juggling in PHP?

PHP uses Type juggling similar to the way Perl uses. Variable is defined in the context in which it is used. It doesn’t require any explicit definition for a function to perform its duties. For example if a string value is assigned to a variable it is defined as string.

what are triggers?

Triggers are the programs need not to be run explicitly.
The functionality should be embeded in driver program and
as the driver program runs the trigger gets executed
automatically.

what about ob_start and ob_flush?

ob_start

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active.


ob_flush


This function does not destroy the output buffer

What is the diffrence between Notify URL and Return URL?

Notify URL and Return URL is used in Paypal Payment Gateway integration
Your Ad Here