Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Funny Pictures MCA Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter



jsp Q &A


Posted Date: 17 Mar 2008    Resource Type: Articles/Knowledge Sharing    Category: General

Posted By: Aparanjitha       Member Level: Gold
Rating:     Points: 5



1)How do I perform browser redirection from a JSP page?

You can use the response implicit object to redirect the browser to a different resource, as:

response.sendRedirect("http://www.exforsys.com/path/error.html");

You can also physically alter the Location HTTP header attribute, as shown below:

<%

response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);

String newLocn = "/newpath/index.html";

response.setHeader("Location",newLocn);

%>

You can also use the: Also note that you can only use this before any output has been sent to the client. I beleve this is the case with the response.sendRedirect() method as well. If you want to pass any paramateres then you can pass using




2)How do I include static files within a JSP page?

Answer Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. The following example shows the syntax:

<%@ include file="copyright.html" %>

Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.

3)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 each executed just once during the lifecycle of a JSP page and are typically declared as JSP declarations:

<%! public void jspInit() {

. . . }

%>

<%!

public void jspDestroy() {

. . . }

%>

4)Can a JSP page process HTML FORM data?

Yes. However, unlike servlets, you are not required to implement HTTP-protocol specific methods like doGet() or doPost() within your JSP page. You can obtain the data for the FORM input elements via the request implicit object within a scriptlet or expression as:

<%

String item = request.getParameter("item");

int howMany = new Integer(request.getParameter("units")).intValue();

%>

or

<%= request.getParameter("item") %>

How do I mix JSP and SSI #include?

If you're just including raw HTML, use the #include directive as usual inside your .jsp file.



But it's a little trickier if you want the server to evaluate any JSP code that's inside the included file. If your data.inc file contains jsp code you will have to use <%@ vinclude="data.inc" %> The is used for including non-JSP files.

5)How can I implement a thread-safe JSP page?

You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive

<%@ page isThreadSafe="false" % > within your JSP page.

6)How do I include static files within a JSP page?

Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. The following example shows the syntax: Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request.

7)How do you prevent the Creation of a Session in a JSP Page and why?

By default, a JSP page will automatically create a session for the request if one does not exist. However, sessions consume resources and if it is not necessary to maintain a session, one should not be created. For example, a marketing campaign may suggest the reader visit a web page for more information. If it is anticipated that a lot of traffic will hit that page, you may want to optimize the load on the machine by not creating useless sessions.

8)What is the page directive is used to prevent a JSP page from automatically creating a session:

<%@ page session="false">

9)Is it possible to share an HttpSession between a JSP and EJB? What happens when I change a value in the HttpSession from inside an EJB?

You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable.This has to be consider as "passed-by-value", that means that it's read-only in the EJB. If anything is altered from inside the EJB, it won't be reflected back to the HttpSession of the Servlet Container.The "pass-byreference" can be used between EJBs Remote Interfaces, as they are remote references. While it IS possible to pass an HttpSession as a parameter to an EJB object, it is considered to be "bad practice (1)" in terms of object oriented design. This is because you are creating an unnecessary coupling between back-end objects (ejbs) and front-end objects (HttpSession). Create a higher-level of abstraction for your ejb's api. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your ejb needs to support a non-http-based client. This higher level of abstraction will be flexible enough to support it. (1) Core J2EE design patterns (2001)

10)Can a JSP page instantiate a serialized bean?

No problem! The useBean 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.

11)Can you make use of a ServletOutputStream object from within a JSP page?

No. You are supposed to make use of only a JSPWriter object (given to you in the form of the implicit object out) for replying to clients. A JSPWriter can be viewed as a buffered version of the stream object returned by response.getWriter(), although from an implementational perspective, it is not. A page author can always disable the default buffering for any page using a page directive as:

<%@ page buffer="none" %>

11)Can we implements interface or extends class in JSP?

No , we can't implements interface or extends class in JSP

12)What are the steps required in adding a JSP Tag Libraries?

1. Create a TLD file and configure the required class Information.

2. Create the Java Implementation Source extending the JSP Tag Lib Class (TagSupport).

3. Compile and package it as loosed class file or as a jar under lib folder in Web Archive File for Class loading.

4. Place the TLD file under the WEB-INF folder.

5. Add reference to the tag library in the web.xml file.





Responses

Author: Deepu    19 Mar 2008Member Level: Diamond   Points : 1
Good work Aparanjitha.


Author: Aparanjitha    19 Mar 2008Member Level: Gold   Points : 2
thanks for ur suggestions and encouragement keep on reading my resoucres and give me some more advises .. Thank you


Author: Deepu    19 Mar 2008Member Level: Diamond   Points : 3
Sure,I will go on reading your postings.If you go on accepting my advices i will give more advises for your development in the site.Keep going.But just keep in mind that your postings are going to be read by hundreds of people throughout the world.


Author: Aparanjitha    19 Mar 2008Member Level: Gold   Points : 2
thnx for your reply to my msg. i mine it that my postings will be read by hundreds of people . so im sure that i will place good resources


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: jsp Q & A
Previous Resource: Usage of Soil in Agriculture
Return to Discussion Resource Index
Post New Resource
Category: General


Post resources and earn money!
 
Related Resources

Watch TV Channels



Contact Us    Editors    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.