servlet container what is difference between servlet container and servlet config?
Servlet container(sub set of web container) is the controller of the servlet.It creates the servlet,initializes,call the service method and finally destroy it.
Servlet config is an object.
what are the necessary conditions to override the init() in servlets? For overriding init()method any rules are there
There are no necessary conditions to override this particular method. In case you are overridding init(ServletConfig config), then make sure to call super.init(config).
Why servlet context is used but not ServletConfig what is use of the servletconfig
2.ServletContex is used to hold information required through out application. One object created for per application and remain active until server is up. while servlet config is used to hold information specific to servlet only. object created one per serlvet and remain active as long as servlet is live.
3.The ServletContext is the way to comminucate with the whole application, and the servletconfig is to communicate just with the actual servlet... Greetings...
JSP server process Explain the server process how will server identifies that and response to corresponding servlet and how it sends to that response to correct user ?
After we request for a jsp. There is a servlet called pagecompilor , which first parses the .jsp page to .java page. then compiles that .java page and produces .class page.
EX.
if we have mypage.jsp
firse myPage-jsp.java then myPage_jsp.class then the source code of resultant JSP-servlet page would look like the fallowing
public myPage_jsp extends httpJspbase {
_jspService() {// what ever is coded in scriplet come here }
// you will not see any _init() or _destroy() methods here
if we look at the signature of httpJspBase
abstract httpJspBase extend httpServlet impliments httpJspPage
Servlets Questions 1)What is web.xml? 2)what is the filter? 3)How to we create a new JSTL class? 4)When we are developing the project which collections mostly used? 5)Difference between reqeust.getAttribute,and request.getParameter?
1)What is web.xml? web.xml is nothing but a deployment descriptor. It describes a web applicants deployment settings. 2)what is the filter? It is an Pluggable web componenet device it allow us to implement or add pre processing or post processing logic in our application. 3)How to we create a new JSTL class? 4)When we are developing the project which collections mostly used? 5)Difference between reqeust.getAttribute,and request.getParameter? getAttribute => Returns an Object, We can set an attribute getParameter => Returns a String, But no setters in parameter
1) What is web.xml?
As this is a deployment descriptor, this is mandatory for an web application to deploy in web/application server. It contains servlets name, url pattern, load on startup, if your application is using any 3rd party tools and if it needs any servlet of that to be initiated etc will be there.
4) When we are developing the project which collections mostly used?
List & Maps interfaces are used most with classes like ArrayList, TreeMap, LinkedHashMap and sometimes Collection.reverseOrder etc
5) Difference between reqeust.getAttribute,and request.getParameter?
Any form (page) data can be accesseed by getParameter() and which ever is set in jsp or servlet as setAttribute can be accessed with getAttribute()
What is the use of Service() in servlets? How is that method invoked?
The container initializes the servlet instance by calling the init .After completing the initialization it calls the service () method passing servlet request and response objects as parameters. service () method is designed in such a way the depending on type of the request method it calls the either doGet() or doPost() method. There is no need to make a explicit call to doGet () or doPost() method.
What information that the ServletResponse interface gives the servlet methods for replying to the client?
What is the servlet life cycle?
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.
JSP Comments What are the ways to write comments in the JSP page? Give example.
Every one know this very simple question best ans my side:-
Two types of comments are allowed in the Jsp page:
1) Hidden comment: This comment will not appear in the output
2) Output comment: This type of comment will appear in the output.
If we have to pass the comment inside the directive then there we use a single line comment i.e. //
advantage of jsp
JSP have all advatages of Java i.e write once run anywhere.JavaServer Pages (JSP) lets you separate the dynamic part of your pages from the static HTML. You simply write the regular HTML in the normal manner, using whatever Web-page-building tools you normally use. You then enclose the code for the dynamic parts in special tags, most of which start with "<%" and end with "%>".
how to disable expression language in jsp
We can use isEliIgnored property or we can disable by using below code..
Code
how to handal error in jsp
When ever Exception accoured redirect the cantrol to the Error page <%@ page ErrorPage="error.jsp" %> In Error page add the bellow line of code <%@ page isErrorPage="true" %> <% out.println(" "); PrintWriter pw=request.getWriter(); Exception.getPrintStakeTrace(pw); out.println(" "); %>Transfer data in JSP How to transfer data over multiple pages?
It can be acheived if we store the data in session scope... using session.setAttribute("name",value);
It can be retrieved in another page by writing session.getAttribute("name"); 2.session 3.request. 4.application
redirect one page to another page
<% response.sendRedirect("RedirectIfSuccessful.html"); %><% String st=request.getParameter("n"); if(st==""){ getServletContext().getRequestDispatcher("/form.jsp").forward(request, response); } else{ getServletContext().getRequestDispatcher("/welcome.jsp").forward(request, response); }
what are the use of implicit objects in jsp?
1.Implicit objects let developers access container-provided services and resources. These objects are defined as implicit because you do not have to explicitly declare them. They are defined in every JSP page and used behind the scenes by the container whether you declare them or not -- although you cannot redeclare them. Because implicit objects are declared automatically, we need only use the reference variable associated with a given object to begin calling methods on it.Functional categories of implicit objects: * Session management: application, session, request, pageContext * Flow control: application, config, pageContext, request, session * Logging and exceptions: application, config, exception, pageContext, request, session * Input/output control: request, response, out * Initialization parameters: config
2.Little addition to JSP implicit Objects: Implicit Objects are 9:
request
response
page
application
session
pagecontext
exception
out
config
These simplify JSP code by providing ready state objects.
Ex: request.getElementById("xyz");
here you are using 'request' object without instantiating it because this object is readily available for you.
why we need web container to Deploy the servlet or jsp ?
Servlets and JSP are server side technologies and should be invoked when we receive request from client browser so web container will act as interface between client request and Servlets and jsp in other words Servlets and jsp will reside under web container in order to server client request. hence we required web container in order to invoke Servlets or jsp Read more at http://www.geekinterview.com/question_details/58434#fD5DJLqlSj4krjtz.99
Jasper Exception in JSP When and why jasperException occurs?
1.It is occurs whenever you miss the tags, or did not close tags properly, or if you put any condition like
int i=request.getparameter("value") if(i==null) { } at this time if i value shows null it gives a Jasper Exception
2.When you are JSP is not parsed by the jasper engine then it throw jasper Exception. Means If you are writing the jsp code not properly and if you put any unavailable resources in the jsp then we will get Jasper Exception
Can we use main method inside JSP? Why?
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 technologies.These will be executed under webcontainer only. Webcontainer will execute JSP/servlet life cycle or callback methods only in order to execute JSP/Servlet.
So throughout the life cycle of JSP/Servlet, the webcontainer will execute init(ServletConfig),service(ServletRequest,ServletResponse),destroy() methods onl
what is jsp
1.sp is server-side technology,which combines both- application logic(java code) and presentation logic(HTML code),so that HTML designers and java code devlopers can work in tandom(simultaniously) by providing there max skills on the application,JSP's reduces javacode by introducing customtags moreover no recompilation problems when code needs to be modified.
2.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.
response.sendredirct end the session first chek than believe
How do you use "synchronized" blocks? Is there other way to prevent next thread to access the resource with out using "synchronized" blocks?
you can use wait and notify methods
Ads