Introduction to JSP
Java Server Pages (JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML. Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations. But most CGI variations, including servlets, make you generate the entire page via your program, even though most of it is always the same. JSP lets you create the two parts separately. Here's an example:
Java Server Pages (JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML. Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations. But most CGI variations, including servlets, make you generate the entire page via your program, even though most of it is always the same. JSP lets you create the two parts separately. Here's an example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>Welcome to Our Store</TITLE></HEAD>
<BODY>
<H1>Welcome to Our Store</H1>
<SMALL>Welcome,
<!-- User name is "New User" for first-time visitors -->
<% out.println(Utils.getUserNameFromCookie(request)); %>
To access your account settings, click
<A HREF="Account-Settings.html">here.</A></SMALL>
<P>
Regular HTML for all the rest of the on-line store's Web page.
</BODY></HTML>
Click on this link to get detail info.
Certain JSP interview question answers...
Q1. What is a JSP and what is it used for?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.Q2. What is difference between custom JSP tags and beans?Custom JSP tag is a tag you defined. You define how a tag, its attributes and its body are interpreted, and then group your tags into collections called tag libraries that can be used in any number of JSP files.To use custom JSP tags, you need to define three separate components:1. the tag handler class that defines the tag\'s behavior2. the tag library descriptor file that maps the XML element names to the tag implementations3. the JSP file that uses the tag libraryWhen the first two components are done, you can use the tag by using taglib directive:<%@ taglib uri="xxx.tld" prefix="..." %>Then you are ready to use the tags you defined.Let's say the tag prefix is test:MyJSPTag or JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags to declare a bean and use to set value of the bean class and use to get value of the bean class.<%=identifier.getclassField() %>Custom tags and beans accomplish the same goals, encapsulating complex behavior into simple and accessible forms.There are several differences:a) Custom tags can manipulate JSP content; beans cannot.b) Complex operations can be reduced to a significantly simpler form with custom tags than with beans. c) Custom tags require quite a bit more work to set up than do beans.d) Custom tags usually define relatively self-contained behavior, whereas beans are often defined in one servlet and used in a different servlet or JSP page.e) Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.Q3. What are the two kinds of comments in JSP and what's the difference between them ?1. JSP CommentExample: <%-- JSP Comment --%>2. HTML CommentExample: <!-- HTML Comment -->Q4. What is JSP technology?Java Server Page is a standard Java extension that is defined on top of the servlet Extensions. The goal of JSP is the simplified creation and management of dynamic Web pages. JSPs are secure, platform-independent, and best of all, make use of Java as a server-side scripting language.Q5. How can a servlet refresh automatically if some new data has entered the database?You can use a client-side Refresh or Server Push.Q6. How many JSP scripting elements and what are they?There are three scripting language elements:1. declarations2. scriptlets3. expressionsQ7. Why are JSP pages the preferred API for creating a web-based client program?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.Q8. Is JSP technology extensible?YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.Q9. What are the implicit objects?Implicit objects are objects that are created by the web container and contain information related to a particular request, page, or application.They are:1. request2. response3. exception4. pageContext5. out6. session7. application8. config
9. pageQ10. Can we use the constructor, instead of init(), to initialize servlet?Yes , of course you can use the constructor instead of init(). There’s nothing to stop you. But you shouldn’t. The original reason for init() was that ancient versions of Java couldn’t dynamically invoke constructors with arguments, so there was no way to give the constructur a ServletConfig. That no longer applies, but servlet containers still will only call your no-arg constructor. So you won’t have access to a ServletConfig or ServletContext.Q11. What is JSP page?A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format such as HTML, SVG, WML, and XML, and JSP elements, which construct dynamic content.
Thank you for sharing this blog. It is very helpful to me. It will improve my knowledge.
ReplyDeleteJ2EE Training in Chennai | JAVA Training Chennai | JAVA J2EE Training in Chennai
The young boys ended up stimulated to read through them and now have unquestionably been having fun with these things.
ReplyDeleteBest Java Training Institute Chennai
I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
ReplyDeleteJava training institute in chennai
thank you for sharing this wonderful posts. awesome informations. learned lot of things from this. core java training in chennai
ReplyDeleteIt is very helpful to me thank you for sharing this blog It will improve my knowledge.
ReplyDeleteReal Trainings provide all IT-Training and Non-IT Training Institutes information in Hyderabad, Bangalore, Chennai . Corporate Companies information and Real time Trainers information at one place. Here students can Compare all Institute's Courses with all detailed information.In Guidewire Training real trainings provides Guidewire Training Institutes in Hyderabad,Guidewire Training , Guidewire Portal training, Guidewire online Training institutes , Guidewire Portal online training classes ,Guidewire Training institutes in hyderabad ,best Guidewire Training courses,Guidewire Portal online training institutes, best training institutes etc..
Thank you for your information. It very nice blog
ReplyDelete<a href="https://www.bestbus.in/”>Bestbus</a> is one of the best online bus ticket booking site . It is providing also car rentals,bus hire for any occasions.Get Tour packages like Ramoji film city, Hyderabad city tour and etc.. at low cost Here payment option is very secure.
Useful Information, your blog is sharing unique information....
ReplyDeleteThanks for sharing!!!
best java developers in india
best java developers in kukatpally
best java developers in gachibowli
This will help them expand their technical brilliance and also have the edge over the competition
ReplyDeletejava training in navalur
Java Training In Chennai
Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!
ReplyDeletebest java training in coimbatore
php training in coimbatore
I am reading your post from the beginning, it was so interesting to read & I feel thanks to you for posting such a good blog, keep updates regularly,
ReplyDeleteDot Net Training Institute in Noida
Thank you for your post. This is useful information.
ReplyDeleteHere we provide our special one's.
iphone training institute in bangalore
lIphone training in Hyderabad
Mobile app training institutes
this blog is very useful for who wants to learn DevOps course if you want to take DevOps training once go through thid blog.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete