Why we need web container to deploy the servlet or JSP ?
I.E why we can not run the application like simple Java program
Server site application contains web resources such as active web resources and passive web resources. Those resides in server passive web resource execution done at browser and active web resources ...
The web container is a Java runtime environment which is responsible for managing life cycle of JSP pages and Servlets. A web container is responsible for instantiating, initializing and invoking Serv...
Share data in two different projects
How to share the data in two different projects in JSP or servlets
A database link can use at database level to transfer data and we can use web service at application level to transfer data between two applications
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...
init() and destroy() methods can be overrided by an JSP page author
init() and destroy() methods can be override. not service() method.
How to maintain values inside form field while uploading image using JSP?
The problem I am facing is that whenever I fill details in the form and then click on upload link then request go to upload.JSP and when after uploading the form the request comes back to registration page(1st page) then the values from all fields disappear
Its better you use Jquery or java script or ajax so that we dont need to completely submit the jsp page just dialog box appear for upload picture and after uploading it will close
Multipart/form-data
It allows the servlet to set the content length and mime type of the reply. Provides an output stream, servletoutputstream and a writer through which the servlet can send the reply data.
The information of buffer size, content length, content type and locale is provided to the client by the servletresponse interface.
What is the servlet life cycle?
Each servlet has the same life cycle:a server loads and initializes the servlet (init())the servlet handles zero or more client requests (service())the server removes the servlet (destroy()) (some servers do this step only when they shut down)
Every servlet follows the same cycle
*The servlet is initialized by calling the init () method.
*The servlet calls service() method to process a clients request.
*The servlet is terminated by calling the destroy() method.
*Finally, servlet is garbage collected by the garbage collector of the JVM.
What are the ways to write comments in the JSP page? Give example.
No, we cant write these codes within scriptlets.
By using Callable Statement like CallableStatement csmt=con.PrepareCall("{PackageName.ProcedureName}"); In jsp U can write these code with in Scriptlet
Code
Jsp container provides a easy way to access standard objects and actions..
Easily saying
1)Auto compilation(translation.....)
2)Not deployment descritpor specific
3)Multiple deployment is avoided.
What is the difference between relative and absolute url?
absolute url is full url relative url is part of url wn we are in app
As there seems to still be confusion about the difference between relative and absolute urls, I thought I'd post a little information and a reference link for everyone. An url that is ABSOLUTE shows ...
How to disable the expression language in a JSP?
isELIgnored="true"
We can use isEliIgnored property or we can disable by using below code..
How will you handle the exception without sending to error page? How will you set a message detail to the exception object?
isErrorPage and errorPage
Example:
The exception will be thrown inside the catch:
<% int x = 5/0;%>
The exception is : ${catchException}
There is an exception: ${catchException.message}
How do you call stored procedures from JSP
we can do same as doing in java wd scriptlet
We can call stored producedure using sql tags in jstl "java5 For example, calling a stored procedure that returns a result set: exec ExampleProcLoadExample ? ...
How to transfer data over multiple pages?
we can set attribute in application session or request attribute.here page wont be use ful bcz scope of page is same page only
1.page
2.session
3.request.
4.application
using these scoped variables we can translate data from one resource to another
ex: request.setAttribute("key","value");
Object o=getAttribute("key");
Pass control from one JSP page to another
Write sample code to pass control from one JSP page to another?
The RequestDispatcher objects forward method to pass the control. The response.sendRedirect method
Code
<% response.sendRedirect("RedirectIfSuccessful.html"); %> <% if(st==""){ getServletContext().getRequestDispatcher("/form.jsp").forward(request, response); } else{ getServletContext().getRequestDispatcher("/welcome.jsp").forward(request, response); } %>
There are 2 ways to redirect the page
1) Use the forward :- By using this
you will get the all the objects in the redirected page.
2) response.sendRedirect("Path") :- In This case the control is not transferred to the next page.
What is need of JSP implicit objects?
application javax.servlet.ServletContext config javax.servlet.ServletConfig exception java.lang.Throwable out javax.servlet.jsp.JspWriter page java.lang.Object PageContext javax.servlet.jsp.PageContex...
When and why jasperexception occurs?
What exactly mean by the following:
jsp-api.jar is missing in the build path.
What happen if it is occurred in Struts 2.1.0 ? while i trying to submit a list value from JSP page in action class : -
why jasper exception occurred when action successfully got the list value - and It give " Unhandled exception in struts : JasperException.
How to write js unit test cases for creating multiple check boxes ?
Can we use main method inside JSP? Why?
Can someone tell me...how a servlet container execute init(),service() and destroy() method in a sequential manner ?
is it true that a servlet container itself contains a main() method which call these methods ?
thanks in advance...
We can use main method in Jsp/servlet, but there is no use. This main() method will not execute throughout the life cycle. Then why should we need to use.Generally these JSP/Servlets are server side t...
NO, There will be one single instance of the servlet in the web-container ,when request arrives to the server a thread will be created rather creating the object. so that multiple request will have ...
single servlet object will be loaded in memory and one thread per request would be created by the container to serve those requests.
Thanks,
Vinay
We cant implement interface in JSP but we can use extends used to extends class not interface
No, We Can't Implement interface in JSP