Answered Questions

  • What happens when we call destroy() method in init() method in servlets

    Yogesh

    • May 9th, 2017

    Nothing Special. It will just execute normal methods. But, it wont work like life cycle method. When JVm invokes these methods then only it will execute like life cycle method.

    Ashwani Gupta

    • Apr 29th, 2016

    overriding init() method wont do any special effect here since web containers initializes the servlets by calling init() method with ServletConfig object as parameter and not the init() method without...

  • Can we override the main method?

    Star Read Best Answer

    Editorial / Best Answer

    ashish_setia  

    • Member Since Oct-2006 | Oct 3rd, 2006


    check out this example

    class Checkmain{
    public static void main(String args[]){
    args[1]="ashish";
    System.out.println("hello ");
    }
    }
    class Checkmain1 extends Checkmain{
    public static void main(String args[]){
    System.out.println("how r u");
    }

    }
    class Jo{
    public static void main(String args[]){
    String S[]=new String[10] ;

    Checkmain.main(S);
    Checkmain1.main(S);
    }}

    vivek

    • Aug 25th, 2017

    Yes you can only do that by overriding main method signature for eg main(String[] args) to main(). Certainly there are no other ways to do that because JVM needs strings array arguments to take comma...

    Dharmendra Singh

    • Sep 15th, 2016

    yes we can"java public class HelloWorld { // arguments are passed using the text field below this editor public static void main(String[] args) { String []s =new Str...

  • What JSP lifecycle methods can I override?

    You cannot override the _jspService() method within a JSP page. You can however, override the jspInit() and jspDestroy() methods within a JSP page. jspInit() can be useful for allocating resources like database connections, network connections, and so forth for the JSP page. It is good programming practice to free any allocated resources within jspDestroy().The jspInit() and jspDestroy() methods are...

    trinadh Subrahmanyam Nune

    • Aug 10th, 2016

    The overriding of JSPINIT method is useful as we are getting the intialization for connections and not the destroy....As after execution of JSP it automatically dies

    Lakshmi

    • Aug 29th, 2012

    Init() and destroy() methods can be overrided by an JSP page author

  • Explain Struts navigation flow

    Star Read Best Answer

    Editorial / Best Answer

    ravi_1229  

    • Member Since Nov-2006 | May 8th, 2009


    1) When first the request is made from a JSP/HTML/XSLT to the server with a particular URI(/something.do), the controll first reaches Web.xml file.

    2) it checks the mapping for /something.do in web.xml and finds the ActionServlet and loads ActionServlet.
    ......
    <servlet-name>action</servlet-name>
            <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    .....

        <servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>*.do</url-pattern>
        </servlet-mapping>

    3) As part of loading ActionServlet calls the init() as every other servlet does.
    (Note: ActionServlet extends HttpServlet only)
    ......................
            <init-param>
                <param-name>config</param-name>
                <param-value>/WEB-INF/struts-config.xml</param-value>
            </init-param>
    ........................

    4) in init() it takes the init-parameters as struts-config.xml and loads the xml file.

    5) then the ActionServlet calls the proceed() of RequestProcessor class.

    6) in proceed() , it checks the appropriate mapping for current request, creates and ActionMapping object and maps the URI to the action in the struts-config.xml.

    7) then it creates an object to ActionForm associated to that action mapped object

    8) calls the setters and reset().

    9) if the action tag in struts-config.xml contains validate="true", then the validate method is called.

    10) if any validation errors, it return to view component (any jsp,XSLT) which is specified as an attribute of input="/error.jsp"

    11) if there are not validation errors, it then creates an Action class for that mapping and search for execute method and executes it.

    12) execute method performs the bussinesslogic which you provide and returns with an ActionForward key.

    13) now the returned key is searched in the mapping object which is specified as forward tag.

    14) it looks for the appropriate view component and performs the getters on that view component and returns the response to the browser.

    Simple, Thats it.

    Thanks
    Ravi