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)What is JSP- JavaServer Pages ?

JavaServer Pages. A server-side technology, JavaServer pages are an extension to the Java servlet technology that was developed by Sun. JSPs have dynamic scripting capability that works in tandem with HTML code, separating the page logic from the static elements -- the actual design and display of the page. Embedded in the HTML page, the Java source code and its extensions help make the HTML more functional, being used in dynamic database queries, for example. JSPs are not restricted to any specific platform or server.

Jsp contains both static and dynamic resources at run time.Jsp extends web server functionalities

2)What are advantages of JSP

whenever there is a change in the code, we dont have to recompile the jsp. it automatically does the compilation. by using custom tags and tag libraries the length of the java code is reduced.

3)What is the difference between include directive & jsp:include action

include directive (): if the file includes static text if the file is rarely changed (the JSP engine may not recompile the JSP if this type of included file is modified) .

if you have a common code snippet that you can reuse across multiple pages (e.g. headers and footers)

jsp:include : for content that changes at runtime .to select which content to render at runtime (because the page and src attributes can take runtime expressions) for files that change often JSP:includenull

4)What are Custom tags. Why do you need Custom tags. How do you create Custom tag

1) Custom tags are those which are user defined.

2) Inorder to separate the presentation logic in a separate class rather than keeping in jsp page we can use custom tags.

3) Step 1 : Build a class that implements the javax.servlet.jsp.tagext.Tag interface as follows. Compile it and place it under the web-inf/classes directory (in the appropriate package structure).

package examples;

import java.io.*; //// THIS PROGRAM IS EVERY TIME I MEAN WHEN U REFRESH THAT PARTICULAR CURRENT DATE THIS CUSTOM TAG WILL DISPLAY

import javax.servlet.jsp.*;

import javax.servlet.jsp.tagext.*;

public class ShowDateTag implements Tag {

private PageContext pageContext;

private Tag parent;

public int doStartTag() throws JspException {

return SKIP_BODY; }

public int doEndTag() throws JspException {

try {

pageContext.getOut().write("" + new java.util.Date());

} catch (IOException ioe) {

throw new JspException(ioe.getMessage());

}

return EVAL_PAGE; }

public void release() {

}

public void setPageContext(PageContext page) {

this.pageContext = page;

}

public void setParent(Tag tag) {

this.parent = tag;

}

public Tag getParent() {

return this.parent; } }

Step 2:Now we need to describe the tag, so create a file called taglib.tld and place it under the web-inf directory."http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd"> 1.0 1.1

myTag http://www.mycompany.com/taglib My own tag library showDate examples.ShowDateTag Show the current date

Step 3 : Now we need to tell the web application where to find the custom tags, and how they will be referenced from JSP pages. Edit the web.xml file under the web-inf directory and insert the following XML fragement.http://www.mycompany.com/taglib /WEB-INF/taglib.tld

Step 4 : And finally, create a JSP page that uses the custom tag.Now restart the server and call up the JSP page! You should notice that every time the page is requested, the current date is displayed in the browser. Whilst this doesn't explain what all the various parts of the tag are for (e.g. the tag description, page context, etc) it should get you going. If you use the tutorial (above) and this example, you should be able to grasp what's going on! There are some methods in context object with the help of which u can get the server (or servlet container) information.

Apart from all this with the help of ServletContext u can implement ServletContextListener and then use the get-InitParametermethod to read context initialization parameters as the basis of data that will be made available to all servlets and JSP pages.

5)What are the implicit objects in JSP & differences between them

There are nine implicit objects in JSP.

1. request : The request object represents httprequest that are trigged by service( ) invocation. javax.servlet

2. response:The response object represents the servers response to request.

javax.servlet

3. pageContext : The page context specifies the single entry point to many of the page attributes and is the convient place to put shared data.

javax.servlet.jsp.pagecontext

4. session : the session object represents the session created by the current user.

javax.Servlet.http.HttpSession

5. application : the application object represents servlet context , obtained from servlet configaration . javax.Servlet.ServletContext

6. out : the out object represents to write the out put stream .

javax.Servlet.jsp.jspWriter

7. Config :the config object represents the servlet config interface from this page,and has scope attribute. javax.Servlet.ServletConfig

8. page : The object is th eInstance of page implementation servlet class that are processing the current request.

java.lang.Object

9. exception : These are used for different purposes and actually u no need to create these objects in JSP. JSP container will create these objects automatically.

java.lang.Throwable

You can directly use these objects.

Example:

If i want to put my username in the session in JSP.

JSP Page: In the about page, i am using session object. But this session object is not declared in JSP file, because, this is implicit object and it will be created by the jsp container.

If u see the java file for this jsp page in the work folder of apache tomcat, u will find these objects are created.

6)What is jsp:usebean. What are the scope attributes & difference between these attributes

page, request, session, application




Responses

Author: Deepu    19 Mar 2008Member Level: Diamond   Points : 1
Good work Aparanjitha.Keep going eith your postings.


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: Tags and Tag Libraries
Previous Resource: jsp Q & A
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.