|
|
|
1)What is difference between scriptlet and expression
With expressions in JSP, the results of evaluating the expression are converted to a string and directly included within the output page. Typically expressions are used to display simple values of variables or return values by invoking a bean's getter methods. JSP expressions begin within tags and do not include semicolons:
But scriptlet can contain any number of language statements, variable or method declarations, or expressions that are valid in the page scripting language. Within scriptlet tags, you can declare variables or methods to use later in the file, write expressions valid in the page scripting language,use any of the JSP mplicit objects or any object declared with a
2)What is Declaration
Declaration is used in JSP to declare methods and variables.To add a declaration, you must use the sequences to enclose your declarations.
3)How do you connect to the database from JSP
To be precise to connect jdbc from jsp is not good idea ofcourse if ur working on dummy projects connecting to msaccess u can very well use the same connection objects amd methods in ur scriplets and define ur connection object in init() method.
But if its real time u can use DAO design patterns which is widely used. for ex u write all ur connection object and and sql quires in a defiened method later use transfer object [TO ]which is all ur fields have get/set methods and call it in business object[BO] so DAO is accessd with precaution as it is the crucial. Finally u define java bean which is a class holding get/set method implementing serialization thus the bean is called in the jsp. So never connect to jdbc directly from client side since it can be hacked by any one to get ur password or credit card info.
4)How do you call stored procedures from JSP
By using callable statement we can call stored procedures and functions from the database.
5)How do you restrict page errors display in the JSP page
set isErrorPage=false
6)How do you pass control from one JSP page to another
we can forward control to aother jsp using jsp action tags forward or incllude
7)How do I have the JSP-generated servlet subclass my own custom servlet class, instead of the default?
One should be very careful when having JSP pages extend custom servlet classes as opposed to the default one generated by the JSP engine. In doing so, you may lose out on any advanced optimization that may be provided by the JSPengine. In any case, your new superclass has to fulfill the contract with the JSPngine by: Implementing the HttpJspPage interface, if the protocol used is HTTP, or implementing JspPage otherwise Ensuring that all the methods in the Servlet interface are declared final Additionally, your servlet superclass also needs to do the following:
The service() method has to invoke the _jspService() method
The init() method has to invoke the jspInit() method
The destroy() method has to invoke jspDestroy()
If any of the above conditions are not satisfied, the JSP engine may throw a translation error. Once the superclass has been developed, you can have your JSP extend it as follows:
<%@ page extends="packageName.ServletName" %<
How does a servlet communicate with a JSP page?
The following code snippet shows how a servlet instantiates a bean and initializes it with FORM data posted by a browser. The bean is then placed into the request, and the call is then forwarded to the JSP page, Bean1.jsp, by means of a request dispatcher for downstream processing.
public void doPost (HttpServletRequest request, HttpServletResponse response)
{
try {
govi.FormBean f = new govi.FormBean();
String id = request.getParameter("id");
f.setName(request.getParameter("name"));
f.setAddr(request.getParameter("addr"));
f.setAge(request.getParameter("age"));
//use the id to compute
//additional bean properties like info
//maybe perform a db query, etc.
// . . .
f.setPersonalizationInfo(info);
request.setAttribute("fBean",f);
getServletConfig().getServletContext().getRequestDispatcher ("/jsp/Bean1.jsp").forward(request, response);
} catch (Exception ex) {
. . .
} }
The JSP page Bean1.jsp can then process fBean, after first extracting it from the default request scope via the useBean action.
jsp:useBean id="fBean" class="govi.FormBean" scope="request"/
jsp:getProperty name="fBean" property="name" /
jsp:getProperty name="fBean" property="addr" /
jsp:getProperty name="fBean" property="age" /
jsp:getProperty name="fBean" property="personalizationInfo" /
|
| Author: Deepu 19 Mar 2008 | Member Level: Diamond Points : 1 |
Good work Aparanjitha.Keep going eith your postings.
|
| Author: Aparanjitha 19 Mar 2008 | Member 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 2008 | Member 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 2008 | Member 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
|