• +91 9971497814
  • info@interviewmaterial.com

Computer Interview Questions Answers

JSP Interview Questions Answers

Question - 41 : - Can a JSP page instantiate a serialized bean?

Answer - 41 : - No problem! The use Bean action specifies the beanName attribute, which can be used for indicating a serialized bean. For example: A couple of important points to note. Although you would have to name your serialized file "filename.ser", you only indicate "filename" as the value for the beanName attribute. Also, you will have to place your serialized file within the WEB-INFjspbeans directory for it to be located by the JSP engine.

Question - 42 : - How does JSP handle runtime exceptions?

Answer - 42 : - Using errorPage attribute of page directive and also we need to specify isErrorPage=true if the current page is intended to URL redirecting of a JSP.

Question - 43 : - How can a servlet refresh automatically if some new data has entered the database?

Answer - 43 : - You can use a client-side Refresh or Server Push.

Question - 44 : - Why are JSP pages the preferred API for creating a web-based client program?

Answer - 44 : - Because no plug-ins or security policy files are needed on the client systems(applet does). Also, JSP pages enable cleaner and more module application design because they provide a way to separate applications programming from web page design. This means personnel involved in web page design do not need to understand Java programming language syntax to do their jobs.

Question - 45 : - Can we implement an interface in a JSP?

Answer - 45 : - No

Question - 46 : - What is a JSP and what is it used for?

Answer - 46 : - Java Server Pages (JSP) is a platform independent presentation layer technology that comes with SUN s J2EE platform. JSPs are normal HTML pages with Java code pieces embedded in them. JSP pages are saved to *.jsp files. A JSP compiler is used in the background to generate a Servlet from the JSP page.

Question - 47 : - How can I set a cookie and delete a cookie from within a JSP page?

Answer - 47 : - Cookie mycook = new Cookie("name","value"); response.addCookie(mycook); Cookie killmycook = new Cookie("mycook","value"); killmycook.setMaxAge(0); killmycook.setPath("/"); killmycook.addCookie(killmycook);

Question - 48 : - How do you restrict page errors display in the JSP page?

Answer - 48 : - You first set "Errorpage" attribute of PAGE directory to the name of the error page (ie Errorpage="error.jsp")in your jsp page .Then in the error jsp page set "isErrorpage=TRUE". When an error occur in your jsp page it will automatically call the error page. How can I enable session tracking for JSP pages if the browser has disabled cookies? We know that session tracking uses cookies by default to associate a session identifier with a unique user. If the browser does not support cookies, or if cookies are disabled, you can still enable session tracking using URL rewriting. URL rewriting essentially includes the session ID within the link itself as a name/value pair. However, for this to be effective, you need to append the session ID for each and every link that is part of your servlet response. Adding the session ID to a link is greatly simplified by means of of a couple of methods: response.encodeURL() associates a session ID with a given URL, and if you are using redirection, response.encodeRedirectURL() can be used by giving the redirected URL as input. Both encodeURL() and encodeRedirectedURL() first determine whether cookies are supported by the browser; if so, the input URL is returned unchanged since the session ID will be persisted as a cookie. Consider the following example, in which two JSP files, say hello1.jsp and hello2.jsp, interact with each other. Basically, we create a new session within hello1.jsp and place an object within this session. The user can then traverse to hello2.jsp by clicking on the link present within the page.Within hello2.jsp, we simply extract the object that was earlier placed in the session and display its contents. Notice that we invoke the encodeURL() within hello1.jsp on the link used to invoke hello2.jsp; if cookies are disabled, the session ID is automatically appended to the URL, allowing hello2.jsp to still retrieve the session object. Try this example first with cookies enabled. Then disable cookie support, restart the brower, and try again. Each time you should see the maintenance of the session across pages. Do note that to get this example to work with cookies disabled at the browser, your JSP engine has to support URL rewriting. hello1.jsp hello2.jsp hello2.jsp <% Integer i= (Integer )session.getValue("num"); out.println("Num value in session is &quo

Question - 49 : - How many JSP scripting elements and what are they?

Answer - 49 : - There are three scripting language elements: --declarations --scriptlets --expressions

Question - 50 : - What are the implicit objects?

Answer - 50 : - Implicit objects are objects that are created by the web container and contain information related to a particular request, page, or application. They are: --request --response --pageContext --session --application --out --config --page --exception

Computer Contributors

krishan
Rajeev Katiyar
Yes Baroda

Share your email for latest updates

Name:
Email:

Our partners