#HttpSession methods
Explore tagged Tumblr posts
Text
How do you handle session management in Java for web applications?
1. Intro to Java Session Management
So, how do you manage sessions in Java for web apps? This is a key question for developers who want to create safe and scalable applications. Session management is all about keeping track of a user's activity on a web app over time. Java has built-in tools for this using HttpSession, cookies, and URL rewriting. Learning how to handle sessions well is an important skill, and taking a Java course in Coimbatore can provide you with hands-on experience. Whether you're just starting out or looking to be a full-stack developer, getting the hang of session concepts is essential for building secure and efficient apps.
2. Understanding HttpSession in Java
So, what about HttpSession? It’s the go-to API for managing sessions in Java. It keeps track of a user's info across several HTTP requests, created by the servlet container. You can access it using request.getSession(). With it, you can store user-specific data like login details or shopping cart items. If you enroll in Java training in Coimbatore, you will learn to create and manage sessions the right way. HttpSession also has methods to end sessions and track them, making it a key part of Java web development.
3. Session Tracking Techniques
When it comes to tracking sessions, there are some common methods: cookies, URL rewriting, and hidden form fields. Cookies are small bits of data saved on the client side, while URL rewriting adds session IDs to URLs. Hidden fields are less used but are still an option. These methods are thoroughly covered in a Java Full Stack Developer Course in Coimbatore. Knowing these options helps you pick the right one for your project. Each method has its benefits based on your app's security and scalability needs.
4. Importance of Session Timeout
Managing session timeout is super important for security and user experience. You can set up timeouts in the web.xml file or by using session.setMaxInactiveInterval(). This helps avoid unused sessions from taking up server resources and lowers the risk of hijacking. Sessions automatically end after a certain time without activity. In a Java course in Coimbatore, you’ll learn how to set timeout values that fit your app's needs. Proper timeout handling is part of building secure Java applications.
5. Secure Session Management Practices
How do you ensure session management is secure in your Java web applications? Always use HTTPS, create new session IDs when a user logs in, and end sessions when they log out. Avoid keeping sensitive info in sessions. Developers taking Java training in Coimbatore learn to apply these practices in real-life projects. Good session management isn't just about saving data; it's about protecting it, which helps safeguard against threats like session fixation.
6. Storing Complex Data in Sessions
When it comes to more complex data, Java sessions can handle that too. You can store objects using session.setAttribute(), which is great for keeping user profiles and cart items. Just remember that the objects need to be serializable and avoid making the session too big. Practical lessons in a Java Full Stack Developer Course in Coimbatore often touch on these points. Good data storage practices can improve performance and keep your code clean.
7. Session Persistence and Scalability
In cases where applications are spread across multiple servers, you have to think about sharing sessions. This can be done with persistent sessions or clustering. Tools like Redis and Memcached help manage state across servers. These ideas are often covered in advanced modules of Java courses in Coimbatore. Learning about session replication and load balancing is key to scaling your app while keeping the state intact.
8. Invalidating and Cleaning Sessions
Another important part of session management is cleaning up. Properly ending sessions is crucial. You can use session.invalidate() when a user logs out to terminate a session. Also, make sure to remove unnecessary attributes to save memory. Good session cleanup is important to prevent memory leaks and keep your app running smoothly. These topics are usually explained in Java training in Coimbatore, teaching students how to manage sessions responsibly.
9. Real-world Applications of Session Management
Understanding the theory is just one part. How does session management play out in the real world? Examples include e-commerce carts, user logins, and personalized dashboards. Sessions are essential for adding a personal touch. The Java Full Stack Developer Course in Coimbatore includes practical projects where session management is used in real web apps. Learning through practical examples helps solidify the concept and prepares developers for actual job roles.
10. Conclusion with Career Opportunities
Getting a handle on session management in Java can really open up job opportunities in backend or full-stack roles. With a solid grasp of HttpSession, tracking methods, and security measures, you'll be able to build secure applications. Whether you’re taking a Java course in Coimbatore or pursuing a full-stack course, this is a key topic you shouldn't overlook. At Xplore IT Corp, we focus on making sure our students are ready for the industry with practical session handling skills and more.
FAQs
1. What’s a session in Java web applications?
A session tracks a single user's activity with a web app over multiple requests and keeps user-specific info.
2. How do I create a session in Java?
You can create one using request.getSession() in servlet-based apps.
3. How do I expire a session in Java?
Use session.invalidate() to end it or set a timeout with setMaxInactiveInterval().
4. What are the options other than HttpSession?
You can use cookies, URL rewriting, hidden fields, or client-side storage depending on what you need.
5. Why is secure session management important?
To protect against threats like session hijacking and to keep user data safe.
#ava servlet session#Java web security#Java session timeout#Session tracking in Java#Cookies in Java#URL rewriting in Java#HttpSession methods#Java EE sessions#Serializable Java object#Java backend development
0 notes
Text
300+ TOP JSP Interview Questions and Answers
JSP Interview Questions for freshers experienced :-
1. 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. 2. What are the two kinds of comments in Jsp and what's the difference between them ? 3. 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. 4. 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. 6. 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: request response pageContext session application out config page exception 6. How many Jsp Scripting Elements and what are they? There are three scripting language elements: declarations scriptlets expressions 7. 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. 8. Is Jsp technology extensible? YES. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries. 9. 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 Servlet Context. 10. How Can A Servlet Refresh Automatically If Some New Data Has Entered The Database? You can use a client-side Refresh or Server Push.
JSP Interview Questions 11. The Code In A Finally Clause Will Never Fail To Execute, Right? Using System.exit(1); in try block will not allow finally code to execute. 12. How Many Messaging Models Do Jms Provide For and What Are They? JMS provide for two messaging models, publish-and-subscribe and point-to-point queuing. 13. What Information Is Needed To Create A Tcp Socket? The Local Systems IP Address and Port Number. And the Remote System’s IPAddress and Port Number. 14. What Class.forname Will Do While Loading Drivers? It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS. 15. How To retrieve warnings? SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object . SQLWarning warning = stmt.getWarnings(); if (warning != null) { while (warning != null) { System.out.println(\"Message: \" + warning.getMessage()); System.out.println(\"SQLState: \" + warning.getSQLState()); System.out.print(\"Vendor error code: \"); System.out.println(warning.getErrorCode()); warning = warning.getNextWarning(); } } 16. How Many Jsp Scripting Elements are there and what are they? There are three scripting language elements: declarations, scriptlets, expressions. 17. In The Servlet 2.4 Specification Singlethreadmodel has Been Deprecated, Why? Because it is not practical to have such model. Whether you set isThreadSafe to true or false, you should take care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the page level. 18. What Are Stored Procedures? How Is It Useful? A stored procedure is a set of statements/commands which reside in the database. The stored procedure is pre-compiled and saves the database the effort of parsing and compiling sql statements every time a query is run. Each database has its own stored procedure language, usually a variant of C with a SQL preproceesor. Newer versions of db’s support writing stored procedures in Java and Perl too. Before the advent of 3-tier/n-tier architecture it was pretty common for stored procs to implement the business logic( A lot of systems still do it). The biggest advantage is of course speed. Also certain kind of data manipulations are not achieved in SQL. Stored procs provide a mechanism to do these manipulations. Stored procs are also useful when you want to do Batch updates/exports/houseKeeping kind of stuff on the db. The overhead of a JDBC Connection may be significant in these cases. 19. How Do I Include Static Files Within A Jsp Page? Static resources should always be included using the JSP include directive. This way, the inclusion is performed just once during the translation phase. Do note that you should always supply a relative URL for the file attribute. Although you can also include static resources using the action, this is not advisable as the inclusion is then performed for each and every request. 20. Why Does Jcomponent have add() And remove() Methods But Component does not? Because JComponent is a subclass of Container, and can contain other components and jcomponents. How can I implement a thread-safe JSP page? - You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive within your JSP page. 21. How Do I Prevent The Output Of My Jsp Or Servlet Pages From Being Cached By The Browser? You will need to set the appropriate HTTP header attributes to prevent the dynamic content output by the JSP page from being cached by the browser. Just execute the following scriptlet at the beginning of your JSP pages to prevent them from being cached at the browser. You need both the statements to take care of some of the older browser versions. 22. How Do You Restrict Page Errors Display In The Jsp Page? You first set "Errorpage" attribute of PAGE directory to the name of the error page (ie Errorpage= "error.jsp")in your jsp page .Then in the error jsp page set "isErrorpage=TRUE". When an error occur in your jsp page it will automatically call the error page. 23. 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 to free any allocated resources within jspDestroy(). The jspInit() and jspDestroy() methods are each executed just once during the lifecycle of a JSP page and are typically declared as JSP declarations: 24. How Do I Perform Browser Redirection From A Jsp Page? You can use the response implicit object to redirect the browser to a different resource, as: response. send Redirect ; You can also physically alter the Location HTTP header attribute, as shown below: You can also use the: Also note that you can only use this before any output has been sent to the client. I beleve this is the case with the response.sendRedirect() method as well. If you want to pass any paramateres then you can pass using. 25. How Does Jsp Handle Run-time Exceptions? You can use the errorPage attribute of the page directive to have uncaught runtime exceptions automatically forwarded to an error processing page. For example: redirects the browser to the JSP page error.jsp if an uncaught exception is encountered during request processing. Within error.jsp, if you indicate that it is an error-processing page, via the directive: the Throwable object describing the exception may be accessed within the error page via the exception implicit object. 26. How Do I Use Comments Within A Jsp Page? You can use "JSP-style" comments to selectively block out code while debugging or simply to comment your scriptlets. JSP comments are not visible at the client. For example: --%> You can also use HTML-style comments anywhere within your JSP page. These comments are visible at the client. For example: Of course, you can also use comments supported by your JSP scripting language within your scriptlets. 27. Is It Possible To Share An Httpsession Between A Jsp And Ejb? What Happens When I Change A Value In The Httpsession From Inside An Ejb? You can pass the HttpSession as parameter to an EJB method, only if all objects in session are serializable. This has to be consider as "passed-by-value", that means that it's read-only in the EJB. If anything is altered from inside the EJB, it won't be reflected back to the HttpSession of the Servlet Container. The "pass-byreference" can be used between EJBs Remote Interfaces, as they are remote references. While it IS possible to pass an HttpSession as a parameter to an EJB object, it is considered to be "bad practice" in terms of object oriented design. This is because you are creating an unnecessary coupling between back-end objects (ejbs) and front-end objects (HttpSession). Create a higher-level of abstraction for your ejb's api. Rather than passing the whole, fat, HttpSession (which carries with it a bunch of http semantics), create a class that acts as a value object (or structure) that holds all the data you need to pass back and forth between front-end/back-end. Consider the case where your ejb needs to support a non-http-based client. This higher level of abstraction will be flexible enough to support it. 28. How Can I Implement A Thread-safe Jsp Page? You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive within your JSP page. 29. How Can I Declare Methods Within My Jsp Page? You can declare methods for use within your JSP page as declarations. The methods can then be invoked within any other methods you declare, or within JSP scriptlets and expressions. Do note that you do not have direct access to any of the JSP implicit objects like request, response, session and so forth from within JSP methods. However, you should be able to pass any of the implicit JSP variables as parameters to the methods you declare. For example: Another Example: file1.jsp: file2.jsp 30. Can I Stop Jsp Execution While In The Midst Of Processing A Request? Yes. Preemptive termination of request processing on an error condition is a good way to maximize the throughput of a high-volume JSP engine. The trick (assuming Java is your scripting language) is to use the return statement when you want to terminate further processing. 31. Can A Jsp Page Process Html Form Data? Yes. However, unlike Servlet, you are not required to implement HTTP-protocol specific methods like doGet() or doPost() within your JSP page. You can obtain the data for the FORM input elements via the request implicit object within a scriptlet or expression as. 32. Is there a way To reference the "this" variable within a Jsp Page? Yes, there is. Under JSP 1.0, the page implicit object is equivalent to "this", and returns a reference to the Servlet generated by the JSP page. 33. Is There A Way I Can Set The Inactivity Lease Period On A Per-session Basis? Typically, a default inactivity lease period for all sessions is set within your JSPengine admin screen or associated properties file. However, if your JSP engine supports the Servlet 2.1 API, you can manage the inactivity lease period on a per-session basis. This is done by invoking the HttpSession.setMaxInactiveInterval() method, right after the session has been created. 34. 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, a fter 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" / 35. Can You Make Use Of A Servletoutputstream Object From Within A Jsp Page? No. You are supposed to make use of only a JSPWriter object (given to you in the form of the implicit object out) for replying to clients. A JSPWriter can be viewed as a buffered version of the stream object returned by response.getWriter(), although from an implementational perspective, it is not. 36. Can A Jsp Page Instantiate A Serialized Bean? No problem! The use Bean action specifies the beanName attribute, which can be used for indicating a serialized bean. For example: A couple of important points to note. Although you would have to name your serialized file "filename.ser", you only indicate "filename" as the value for the beanName attribute. Also, you will have to place your serialized file within the WEB-INFjspbeans directory for it to be located by the JSP engine. 37. What Is Jsp? Let's consider the answer to that from two different perspectives: that of an HTML designer and that of a Java programmer. If you are an HTML designer, you can look at JSP technology as extending HTML to provide you with the ability to seamlessly embed snippets of Java code within your HTML pages. These bits of Java code generate dynamic content, which is embedded within the other HTML/XML content you author. Even better, JSP technology provides the means by which programmers can create new HTML/XML tags and JavaBeans components, which provide new features for HTML designers without those designers needing to learn how to program. Note: A common misconception is that Java code embedded in a JSP page is transmitted with the HTML and executed by the user agent (such as a browser). This is not the case. A JSP page is translated into a Java servlet and executed on the server. JSP statements embedded in the JSP page become part of the servlet generated from the JSP page. The resulting servlet is executed on the server. It is never visible to the user agent. If you are a Java programmer, you can look at JSP technology as a new, higher-level means to writing servlets. Instead of directly writing servlet classes and then emitting HTML from your servlets, you write HTML pages with Java code embedded in them. The JSP environment takes your page and dynamically compiles it. Whenever a user agent requests that page from the Web server, the servlet that was generated from your JSP code is executed, and the results are returned to the user. 38. How Do I Mix Jsp And Ssi #include? What Is The Difference Between Include Directive & Jsp:include Action? If you're just including raw HTML, use the #include directive as usual inside your .jsp file. But it's a little trickier if you want the server to evaluate any JSP code that's inside the included file. If your data.inc file contains jsp code you will have to use The is used for including non-JSP files. include directive - - as is the case with all other directives in a JSP page, this include directive is also processed at the time when the JSP page is translated into its equivalent servlet. This directive simply causes the contents of the specified file to be pasted into the JSP page at the place where the page contains this directive. Irrespective of whether the included resource is a static resource or a JSP page - only the contents of the file are pasted (and not the processed results). This directive is normally used for including static resources only - like, banner, header, footer, etc. for the obvious reason. include action - this include action is executed at run time and the specified 'page' is first executed and then the result of that 'page' is appended to the response object of the calling JSP at the point where the tag occurs. Obviously if the specified page is a static resource then the contents of it are included as there won't be an executed result in that case. This action allows additional parameters to be passed via child element of this include action element. 39. How Do You Prevent The Creation Of A Session In A Jsp Page And Why? What Is The Difference Between Include Directive & Jsp:include Action? By default, a JSP page will automatically create a session for the request if one does not exist. However, sessions consume resources and if it is not necessary to maintain a session, one should not be created. For example, a marketing campaign may suggest the reader visit a web page for more information. If it is anticipated that a lot of traffic will hit that page, you may want to optimize the load on the machine by not creating useless sessions. 40. How Can I Set A Cookie And Delete A Cookie From Within A Jsp Page? A cookie, mycookie, can be deleted using the following scriptlet: 41. How Do You Connect To The Database From Jsp? A Connection to a database can be established from a jsp page by writing the code to establish a connection using a jsp scriptlets. Further then you can use the resultset object "res" to read data in the following way. 42. What Is The Page Directive Is Used To Prevent A Jsp Page From Automatically Creating A Session? 43. How Do You Delete A Cookie Within A Jsp? Cookie mycook = new Cookie("name","value"); response.addCookie(mycook); Cookie killmycook = new Cookie("mycook","value"); killmycook.setMaxAge(0); killmycook.setPath("/"); killmycook.addCookie(killmycook); 44. Can We Implement An Interface In A Jsp? No 45. What Is The Difference Between Servletcontext And Pagecontext? ServletContext: Gives the information about the container PageContext: Gives the information about the Request. 46. What Is The Difference In Using Request.getrequestdispatcher() And Context.getrequestdispatcher()? request.getRequestDispatcher(path): In order to create it we need to give the relative path of the resource context.getRequestDispatcher(path): In order to create it we need to give the absolute path of the resource. 47. How To Pass Information From Jsp To Included Jsp? Using tag. 48. How Is Jsp Include Directive Different From Jsp Include Action. ? When a JSP include directive is used, the included file's code is added into the added JSP page at page translation time, this happens before the JSP page is translated into a servlet. While if any page is included using action tag, the page's output is returned back to the added page. This happens at runtime. 49. Can We Override The Jspinit(), _jspservice() And Jspdestroy() Methods? We can override jspinit() and jspDestroy() methods but not _jspService(). 50. Why Is _jspservice() Method Starting With An '_' While Other Life Cycle Methods Do Not? _jspService() method will be written by the container hence any methods which are not to be overridden by the end user are typically written starting with an '_'. This is the reason why we don't override _jspService() method in any JSP page. 51. What Happens When A Page Is Statically Included In Another Jsp Page? An include directive tells the JSP engine to include the contents of another file (HTML, JSP, etc.) in the current page. This process of including a file is also called as static include. 52. A Jsp Page, Include.jsp, Has A Instance Variable "int A", Now This Page Is Statically Included In Another Jsp Page, Index.jsp, Which Has A Instance Variable "int A" Declared. What Happens When The Index.jsp Page Is Requested By The Client? Compilation error, as two variables with same name can't be declared. This happens because, when a page is included statically, entire code of included page becomes part of the new page. at this time there are two declarations of variable 'a'. Hence compilation error. 53. Can You Override Jspinit() Method? If Yes, In Which Cases? yes, we can. We do it usually when we need to initialize any members which are to be available for a servlet/ JSP throughout its lifetime. 54. What Is The Difference Between Directive Include And Jsp Include? include directive : The file gets included at the compile time. it is static in nature.output comes with jsp page but whole file contains is included in jsp then compilation is done. action tag : The file gets included at the run time. This is faster. it is dynamic in nature.output of yhe file willbe included in the jsp file. 55. What Is The Difference Between Requestdispatcher And Sendredirect? RequestDispatcher: server-side redirect with request and response objects. sendRedirect : Client-side redirect with new request and response objects. 56. How Does Jsp Handle Runtime Exceptions? Using errorPage attribute of page directive and also we need to specify isErrorPage=true if the current page is intended to URL redirecting of a JSP. 57. How Can My Application Get To Know When A Httpsession Is Removed? Define a Class HttpSessionNotifier which implements HttpSessionBindingListener and implement the functionality what you need in valueUnbound() method. Create an instance of that class and put that instance in HttpSession. 58. What Is A Output Comment? A comment that is sent to the client in the viewable page source.The JSP engine handles an output comment as uninterpreted HTML text, returning the comment in the HTML output sent to the client. You can see the comment by viewing the page source from your Web browser. JSP Syntax Example 1 Displays in the page source: 59. What Is A Hidden Comment? A comments that documents the JSP page but is not sent to the client. The JSP engine ignores a hidden comment, and does not process any code within hidden comment tags. A hidden comment is not sent to the client, either in the displayed JSP page or the HTML page source. The hidden comment is useful when you want to hide or "comment out" part of your JSP page. You can use any characters in the body of the comment except the closing --%> combination. If you need to use --%> in your comment, you can escape it by typing --%\>. JSP Syntax Examples 60. What Is A Expression? An expression tag contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file. Because the value of an expression is converted to a String, you can use an expression within text in a JSP file. Like You cannot use a semicolon to end an expression. 61. What Is A Declaration? A declaration declares one or more variables or methods for use later in the JSP source file. A declaration must contain at least one complete declarative statement. You can declare any number of variables or methods within one declaration tag, as long as they are separated by semicolons. The declaration must be valid in the scripting language used in the JSP file. 62. What Is A Scriptlet? A 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 (see also Declaration). Write expressions valid in the page scripting language (see also Expression). Use any of the JSP implicit objects or any object declared with a tag. You must write plain text, HTML-encoded text, or other JSP tags outside the scriptlet. Scriptlets are executed at request time, when the JSP engine processes the client request. If the scriptlet produces output, the output is stored in the out object, from which you can display it. 63. What Are Implicit Objects? List Them? Certain objects that are available for the use in JSP documents without being declared first. These objects are parsed by the JSP engine and inserted into the generated servlet. The implicit objects re listed below request response pageContext session application out config page exception. 64. Difference Between Forward And Sendredirect? When you invoke a forward request, the request is sent to another resource ohe server, without the client being informed that a different resource is going to process the request. This process occurs completly with in the web container. When a sendRedirtect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completly new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward. 65. What Are The Different Scope Valiues For The ? The different scope values for are 1. page 2. request 3.session 4.application. 66. Explain The Life-cycle Mehtods In Jsp? The generated servlet class for a JSP page implements the HttpJspPage interface of the javax.servlet.jsp package. Hte HttpJspPage interface extends the JspPage interface which inturn extends the Servlet interface of the javax.servlet package. the generated servlet class thus implements all the methods of the these three interfaces. The JspPage interface declares only two mehtods - jspInit() and jspDestroy() that must be implemented by all JSP page regardless of the client-server protocol. However the JSP specification has provided the HttpJspPage interfaec specifically for the JSp pages serving HTTP requests. This interface declares one method_jspService(). The jspInit()- The container calls the jspInit() to initialize te servlet instance.It is called before any other method, and is called only once for a servlet instance. The _jspservice()- The container calls the _jspservice() for each request, passing it the request and the response objects. The jspDestroy()- The container calls this when it decides take the instance out of service. It is the last method called n the servlet instance. 67. What's A Better Approach For Enabling Thread-safe Servlets And Jsps? Singlethreadmodel Interface Or Synchronization? Although the SingleThreadModel technique is easy to use, and works well for low volume sites, it does not scale well. If you anticipate your users to increase in the future, you may be better off implementing explicit synchronization for your shared data. The key however, is to effectively minimize the amount of code that is synchronzied so that you take maximum advantage of multithreading. Also, note that SingleThreadModel is pretty resource intensive from the server\'s perspective. The most serious issue however is when the number of concurrent requests exhaust the servlet instance pool. In that case, all the unserviced requests are queued until something becomes free - which results in poor performance. Since the usage is non-deterministic, it may not help much even if you did add more memory and increased the size of the instance pool. 68. What Is The Difference Between Jsp And Servlets ? JSP is used mainly for presentation only. A JSP can only be HttpServlet that means the only supported protocol in JSP is HTTP. But a servlet can support any protocol like HTTP, FTP, SMTP etc. 69. 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: the tag handler class that defines the tag's behavior ,the tag library descriptor file that maps the XML element names to the tag implementations and the JSP file that uses the tag library. JavaBeans are Java utility classes you defined. Beans have a standard format for Java classes. You use tags . Custom tags and beans accomplish the same goals -- encapsulating complex behavior into simple and accessible forms. There are several differences. Custom tags can manipulate JSP content; beans cannot. Complex operations can be reduced to a significantly simpler form with custom tags than with beans. Custom tags require quite a bit more work to set up than do beans. 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. Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions. 70. What Are The Different Ways For Session Tracking? Cookies, URL rewriting, HttpSession, Hidden form fields. 71. What Mechanisms Are Used By A Servlet Container To Maintain Session Information? Cookies, URL rewriting, and HTTPS protocol information are used to maintain session information. 72. Difference Between Get And Post? In GET your entire form submission can be encapsulated in one URL, like a hyperlink. query length is limited to 255 characters, not secure, faster, quick and easy. The data is submitted as part of URL. In POST data is submitted inside body of the HTTP request. The data is not visible on the URL and it is more secure. 73. What Is Session? The session is an object used by a servlet to track a user's interaction with a Web application across multiple HTTP requests. The session is stored on the server. 74. What Is Servlet Mapping? The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets. 75. What Is Servlet Context ? The servlet context is an object that contains a information about the Web application and container. Using the context, a servlet can log events, obtain URL references to resources, and set and store attributes that other servlets in the context can use. 76. What Is A Servlet ? servlet is a java program that runs inside a web container. 77. How Is Scripting Disabled? Scripting is disabled by setting the scripting-invalid element of the deployment descriptor to true. It is a sub element of jsp-property-group. Its valid values are true and false. The syntax for disabling scripting is as follows: *.jsp true 78. What Is A Jsp Expression? A JSP expression is used to write an output without using the out.print statement. It can be said as a shorthand representation for scriptlets. An expression is written between the tags. It is not required to end the expression with a semicolon, as it implicitly adds a semicolon to all the expressions within the expression tags. 79. What Are Jsp Declarations? As the name implies, JSP declarations are used to declare class variables and methods in a JSP page. They are initialized when the class is initialized. Anything defined in a declaration is available for the whole JSP page. A declaration block is enclosed between the tags. A declaration is not included in theservice() method when a JSP is translated to a servlet. 80. What Is The Jsp:plugin Action ? This action lets you insert the browser-specific OBJECT or EMBED element needed to specify that the browser run an applet using the Java plugin. 81. What Are Scripting Elements? JSP scripting elements let you insert Java code into the servlet that will be generated from the current JSP page. There are three forms: Expressionsof the form that are evaluated and inserted into the output, Scriptletsof the form that are inserted into the servlet's service method, Declarationsof the form that are inserted into the body of the servlet class, outside of any existing methods. 82. What Is The Standard Action? The standard action is used with or to pass parameter names and values to the target resource. The syntax of the standard action is as follows: 83. What Is The Jsp:getproperty Action? The action is used to access the properties of a bean that was set using the action. The container converts the property to a String as follows: If it is an object, it uses the toString() method to convert it to a String. If it is a primitive, it converts it directly to a String using the valueOf() method of the corresponding Wrapper class. The syntax of the method is: Here, name is the id of the bean from which the property was set. The property attribute is the property to get. A user must create or locate a bean using the action before using the action. 84. Differentiate Between Pagecontext.include And Jsp:include? The standard action and thepageContext.include() method are both used to include resources at runtime. However, thepageContext.include() method always flushes the output of the current page before including the other components, whereas flushes the output of the current page only if the value = of flush is explicitly set to true as follows: 85. What Is The Standard Action? The standard action enables the current JSP page to include a static or a dynamic resource at runtime. In contrast to the include directive, the include action is used for resources that change frequently. The resource to be included must be in the same context.The syntax of the standard action is as follows: Here, targetPage is the page to be included in the current JSP. 86. What Is The Standard Action? The standard action is used to locate an existing JavaBean or to create a JavaBean if it does not exist. It has attributes to identify the object instance, to specify the lifetime of the bean, and to specify the fully qualified classpath and type. 87. What Are The Standard Actions Available In Jsp? The standard actions available in JSP are as follows: It includes a response from a servlet or a JSP page into the current page.It differs from an include directive in that it includes a resource at request processing time, whereas the include directive includes a resource at translation time. It forwards a response from a servlet or a JSP page to another page. It makes a JavaBean available to a page and instantiates the bean. It sets the properties for a JavaBean. It gets the value of a property from a JavaBean component and adds it to the response. It is used in conjunction with ;, ; to add a parameter to a request. These parameters are provided using the name-value pairs. It is used to include a Java applet or a JavaBean in the current JSP page. 88. What Are The Jsp Standard Actions? The JSP standard actions affect the overall runtime behavior of a JSP page and also the response sent back to the client. They can be used to include a file at the request time, to find or instantiate a JavaBean, to forward a request to a new page, to generate a browser-specific code, etc. Ex: include, forward, useBean,etc. 89. What Is The Include Directive? There are thirteen attributes defined for a page directive of which the importantattributes are as follows: The include directive is used to statically insert the contents of a resource into the current JSP. This enables a user to reuse the code without duplicating it, and includes the contents of the specified file at the translation time. The syntax of the include directive is as follows: This directive has only one attribute called file that specifies the name of the file to be included. 90. What Are The Attributes Of Page Directive? There are thirteen attributes defined for a page directive of which the important attributes are as follows: import: It specifies the packages that are to be imported. session: It specifies whether a session data is available to the JSP page. contentType: It allows a user to set the content-type for a page. isELIgnored: It specifies whether the EL expressions are ignored when a JSP is translated to a servlet. 91. What Is Page Directive? A page directive is to inform the JSP engine about the headers or facilities that page should get from the environment. Typically, the page directive is found at the top of almost all of our JSP pages. There can be any number of page directives within a JSP page (although the attribute – value pair must be unique). The syntax of the include directive is: Example: 92. What Are Jsp Directives? • JSP directives are messages for the JSP engine. i.e., JSP directives serve as a message from a JSP page to the JSP container and control the processing of the entire page. • They are used to set global values such as a class declaration, method implementation, output content type, etc. • They do not produce any output to the client. • Directives are always enclosed within tag. • Ex: page directive, include directive, etc. 93. 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. 94. How Do I Use A Scriptlet To Initialize A Newly Instantiated Bean? A jsp:useBean action may optionally have a body. If the body is specified, its contents will be automatically invoked when the specified bean is instantiated. Typically, the body will contain scriptlets or jsp:setProperty tags to initialize the newly instantiated bean, although you are not restricted to using those alone. The following example shows the "today" property of the Foo bean initialized to the current date when it is instantiated. Note that here, we make use of a JSP expression within the jsp:setProperty action. value=""/ > 95. What Is The Page Directive Is Used To Prevent A Jsp Page From Automatically Creating A Session: 96. What Are The Steps Required In Adding A Jsp Tag Libraries? Create a TLD file and configure the required class Information. Create the Java Implementation Source extending the JSP Tag Lib Class (TagSupport). Compile and package it as loosed class file or as a jar under lib folder in Web Archive File for Class loading. Place the TLD file under the WEB-INF folder. Add reference to the tag library in the web.xml file. 97. Outline The Major Difference Between The Session And Cookie? Sessions are always stored in the server side whereas cookies are always stored in the client side. 98. How Method Is Declared Within Jsp Page? Methods can be declared for use within JSP page as declaration and this method can be invoked within any other method which is declared or within JSP scriptlets or expressions. Direct access to the JSP implicit objects like request, response, session etc is forbidden within JSP methods but implicit Java server page variable is allowed to pass as parameters to the method which is declared. 99. Is It Possible By A Jsp Page To Process Html Form Data? Yes it is possible by simply obtaining the data from the FORM input via the request implicit object which lies with a scriptlet or expression but it doesn't require to implement any HTTP – Protocol methods like goGet() or doPost() within the JSP page. 100. How Cookies Is Deleted In Jsp? There are two ways by which the cookies can be deleted in JSP. Firstly, by setting the setMaxAge() of the cookie class to zero. And secondly by setting a timer in the header file that is response. setHeader(expires {Mention the time} attribute), which will delete the cookies after that prescribed time. 101. What Are Custom Tags And Why It Is Needed? JSP tags are extended by creating a custom set of tags which is called as tag library (taglib). The page which uses custom tags declares taglib and uniquely names, defines and associates a tag prefix to differentiate the usage of those tags. 102. Outline The Difference Between Java Server Page Forward And Servlet Forward Method? The only minor difference between both the methods is that Java Server page forward method can’t forward to another JSP page in another web application or container whereas servlet forward method can do so. 103. State The Difference Between The Expression And Scriptlet? JSP, Expressions is used to display the values of variable or to return the values by invoking the getter methods. However, JSP expressions begins with and does not have semicolon at the end of the expression. Scriptlet can contain variable, method or expressions that are valid within the page scripting language. Within the scripting tags and page scripting language any valid operations can be performed. 104. How A Run - Time Application Is Handled In Jsp? In JSP the errorpage attribute of the page is used as a directive to have uncaught run – time exceptions and which is automatically forwarded to an page which processes the error. If an uncaught exception is encountered while processing the request, then the browser redirects to the JSP error page. 105. What Is Declaration In Jsp? In Java Server pages Declaration is used to declare and define variables and methods that can be used in the Java Server Pages. The variable which is declared is initialized once and it retain its value for every subsequent client request. 106. How To Override The Lifecycle Methods Of Jsp? Lifecycle method jspService() cannot be overridden within a JSP page however methods like jspInit() and jspDestroy() can be overridden within a JSP page. Method jspInit() is used for allocating resource while method jspDestroy() is used to free allocated resource. But it should be kept in mind that during the lifecycle of a Java Server Page both the method jsplnit() and jspDestroy() is executed once and are declared as JSP declarations. 107. How Jsp Calls A Stored Procedure? Java Server Pages possess all the characteristics of java and to call and have similar syntax to call a function. Functions and stored procedures of a database can be called by using the statement callable. Another way to call the stored procedure is by writing the JDBC code in between the tag of scriptlet tab.write. 108. What Are The Implicit Objects In Jsp? There are all total 9 implicit objects in JSP. Application interface refers to the web application’s interface whereas Session interface refers to the user’s session. Request interface refers to the page which is currently requested whereas Response interface refers to the response which is currently made by the user. Config interface refers to the servlet configuration. Class like out, page, page Context and exception refers to the output stream of the page, servlet instance of the page, environment of the page, error handling respectively. 109. How Servlet Differ From Jsp? Both Servlet and Java Server Pages are API which generate dynamic web content. A servlet is nothing but a java class which implements the interface to run within a web and on the other hand Java server pages is a bit complicated thing which contain a mixture of Java scripts, Java directives, Java elements and HTML. The main difference among both servlet and Java server pages is that JSP is document oriented and servlet on the other hand act likes a program. 110. What Is Jsp? Describe Its Concept? JSP is a technology that combines HTML/XML markup languages and elements of Java programming Language to return dynamic content to the Web client, It is normally used to handle Presentation logic of a web application, although it may have business logic. 111. What Are The Lifecycle Phases Of A Jsp? JSP page looks like a HTML page but is a servlet. When presented with JSP page the JSP engine does the following 7 phases. Page translation: -page is parsed, and a java file which is a servlet is created. Page compilation: page is compiled into a class file Page loading : This class file is loaded. Create an instance :- Instance of servlet is created jspInit() method is called _jspService is called to handle service calls _jspDestroy is called to destroy it when the servlet is not required. 112. What Is A Translation Unit? JSP page can include the contents of other HTML pages or other JSP files. This is done by using the include directive. When the JSP engine is presented with such a JSP page it is converted to one servlet class and this is called a translation unit, Things to remember in a translation unit is that page directives affect the whole unit, one variable declaration cannot occur in the same unit more than once, the standard action jsp:useBean cannot declare the same bean twice in one unit. 113. How Is Jsp Used In The Mvc Model JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the JSP for rendering on to the client. 114. What Are Context Initialization Parameters Context initialization parameters are specified by the in the web.xml file, these are initialization parameter for the whole application and not specific to any servlet or JSP. 115. What's The Difference Between Forward And Sendredirect? When you invoke a forward request, the request is sent to another resource on the server, without the client being informed that a different resource is going to process the request. This process occurs completely with in the web container And then returns to the calling method. When a sendRedirect method is invoked, it causes the web container to return to the browser indicating that a new URL should be requested. Because the browser issues a completely new request any object that are stored as request attributes before the redirect occurs will be lost. This extra round trip a redirect is slower than forward. 116. How Can You Store International / Unicode Characters Into A Cookie? One way is, before storing the cookie URLEncode it. URLEnocder.encoder(str); And use URLDecoder.decode(str) when you get the stored cookie. 117. In The Servlet 2.4 Specification Singlethreadmodel Has Been Deprecates, Why? Because it is not practical to have such model. Whether you set isThreadSafe to true or false, you should take care of concurrent client requests to the JSP page by synchronizing access to any shared objects defined at the page level. JSP Questions and Answers Pdf Download Read the full article
0 notes
Text
JSP Interview questions
What is JSP?
Java Server Pages technology (JSP) is used to create dynamic web page. It is an extension to the servlet technology. A JSP page is internally converted into servlet.
What are advantages of using JSP?
JSP has several advantages as listed below
JSP Performance is significantly better because JSP allows embedding Dynamic Elements in HTML Pages itself. JSP are always compiled before it’s processed by the server unlike CGI/Perl which requires the server to load an interpreter and the target script each time the page is requested. JSP are built on top of the Java Servlets API, so like Servlets, JSP also has access to all the powerful Enterprise Java APIs, including JDBC, JNDI, EJB, JAXP etc. JSP pages can be used in combination with servlets that handle the business logic, the model supported by Java servlet template engines.
What are the life-cycle methods for a jsp?
JSP life cycle methods are listed below :
public void jspInit() : It is invoked only once, same as init method of servlet. public void _jspService(ServletRequest request,ServletResponse) throws ServletException,IOException : It is invoked at each request, same as service() method of servlet. public void jspDestroy() : It is invoked only once, same as destroy() method of servlet.
What are the advantages of JSP over Active Server Pages (ASP)?
The advantages of JSP are twofold.
First, the dynamic part is written in Java, not Visual Basic or other MS specific language, so it is more powerful and easier to use.
Second, it is portable to other operating systems and non-Microsoft Web servers.
What are the advantages of JSP over Pure Servlets?
It is more convenient to write (and to modify!) regular HTML than to have plenty of println statements that generate the HTML. Other advantages are:
Embedding of Java code in HTML pages. Platform independence. Creation of database-driven Web applications. Server-side programming capabilities.
What are the advantages of JSP over JavaScript?
JavaScript can generate HTML dynamically on the client but can hardly interact with the web server to perform complex tasks like database access and image processing etc.
What is difference between hide comment and output comment?
The jsp comment is called hide comment whereas html comment is called output comment. If user views the source of the page, the jsp comment will not be shown whereas html comment will be shown.
Explain lifecycle of a JSP.
A JSP Lifecycle consists of following steps:
Compilation: When a browser asks for a JSP, the JSP engine first checks to see whether it needs to compile the page. If the page has never been compiled, or if the JSP has been modified since it was last compiled, the JSP engine compiles the page.
The compilation process involves three steps:
Parsing the JSP.
Turning the JSP into a servlet.
Compiling the servlet.
Initialization: When a container loads a JSP it invokes the jspInit() method before servicing any requests Execution: Whenever a browser requests a JSP and the page has been loaded and initialized, the JSP engine invokes the _jspService() method in the JSP.The _jspService() method of a JSP is invoked once per a request and is responsible for generating the response for that request and this method is also responsible for generating responses to all seven of the HTTP methods ie. GET, POST, DELETE etc. Cleanup: The destruction phase of the JSP life cycle represents when a JSP is being removed from use by a container.The jspDestroy() method is the JSP equivalent of the destroy method for servlets.
What are the JSP implicit objects?
JSP provides 9 implicit objects by default. They are as follows:
out : the out is type of JspWriter request : the request is type of HttpServletRequest response : the response is type of HttpServletResponse config : the config is type of ServletConfig session : the session is type of HttpSession application : the application is type of ServletContext pageContext : the pageContext is type of PageContext page : the page is type of Object, it refer to this exception : the exception is type of Throwable
What is a sciptlet in JSP and what is its syntax?
A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.
Following is the syntax of Scriptlet: ? 1
<% some java code %>
What are JSP declarations?
A declaration declares one or more variables or methods that you can use in Java code later in the JSP file. You must declare the variable or method before you use it in the JSP file. ? 1
<%! some variable declaration; %>
What are JSP expressions?
A JSP expression element contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file.
The expression element can contain any expression that is valid according to the Java Language Specification but you cannot use a semicolon to end an expression.
Its syntax is: ? 1
<%= expression %>
What are JSP comments?
JSP comment marks text or statements that the JSP container should ignore. A JSP comment is useful when you want to hide or “comment out” part of your JSP page.
Following is the syntax of JSP comments: ? 1
<%-- This is JSP comment --%>
What are JSP Directives?
A JSP directive affects the overall structure of the servlet class. It usually has the following form: ? 1
<%@ directive attribute="value" %>
What are the types of directive tags?
The types directive tags are as follows:
<%@ page ... %> : Defines page-dependent attributes, such as scripting language, error page, and buffering requirements. <%@ include ... %> : Includes a file during the translation phase. <%@ taglib ... %> : Declares a tag library, containing custom actions, used in the page.
What are JSP actions?
JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin.
Its syntax is as follows: ? 1
Name some JSP actions.
Some of the JSP Actions : jsp:include, jsp:useBean,jsp:setProperty,jsp:getProperty, jsp:forward,jsp:plugin,jsp:element, jsp:attribute, jsp:body, jsp:text
What are JSP literals?
Literals are the values, such as a number or a text string, that are written literally as part of a program code. The JSP expression language defines the following literals:
Boolean: true and false Integer: as in Java Floating point: as in Java String: with single and double quotes; ” is escaped as \”, ‘ is escaped as \’, and \ is escaped as \\. Null: null
What is a page directive?
The page directive is used to provide instructions to the container that pertain to the current JSP page. You may code page directives anywhere in your JSP page.
What is difference between include directive and include action?
include directive
The include directive includes the content at page translation time. The include directive includes the original content of the page so page size increases at runtime. It’s better for static pages.
include action
The include action includes the content at request time. The include action doesn’t include the original content rather invokes the include() method of Vendor provided class. It’s better for dynamic pages.
Is JSP technology extensible?
Yes. JSP technology is extensible through the development of custom actions, or tags, which are encapsulated in tag libraries.
How can I implement a thread-safe JSP page? What are the advantages and Disadvantages of using it?
You can make your JSPs thread-safe by having them implement the SingleThreadModel interface. This is done by adding the directive <%@ page isThreadSafe="false" %> within your JSP page.
How can we handle the exceptions in JSP ?
There are two ways to perform exception handling, one is by the errorPage element of page directive, and second is by the error-page element of web.xml file.
What are the two ways to include the result of another page. ?
There are two ways to include the result of another page:
By include directive By include action
Can we use the exception implicit object in any jsp page?
No. The exception implicit object can only be used in the error page which defines it with the isErrorPage attribute of page directive.
How is JSP used in the MVC model?
JSP is usually used for presentation in the MVC pattern (Model View Controller ) i.e. it plays the role of the view. The controller deals with calling the model and the business classes which in turn get the data, this data is then presented to the JSP for rendering on to the client.
What are the different scope values for the tag?
There are 4 values:
page request session application
What is the difference between ServletContext and PageContext?
ServletContext gives the information about the container whereas PageContext gives the information about the Request.
What is the difference in using request.getRequestDispatcher() and context.getRequestDispatcher()?
request.getRequestDispatcher(path) is used in order to create it we need to give the relative path of
the resource whereas context.getRequestDispatcher(path) in order to create it we need to give the absolute path of the resource.
What is EL in JSP?
The Expression Language(EL) is used in JSP to simplify the accessibility of objects. It provides many objects that can be used directly like param, requestScope, sessionScope, applicationScope, request, session etc.
What is basic differences between the JSP custom tags and java beans?
Custom tags can manipulate JSP content whereas beans cannot. Complex operations can be reduced to a significantly simpler form with custom tags than with beans. Custom tags require quite a bit more work to set up than do beans. Custom tags are available only in JSP 1.1 and later, but beans can be used in all JSP 1.x versions.
Can an interface be implemented in the jsp file?
No.
What is JSTL?
JSP Standard Tag Library is library of predefined tags that ease the development of JSP.
How many tags are provided in JSTL?
There are 5 type of JSTL tags.
core tags sql tags xml tags internationalization tags functions tags
Which directive is used in jsp custom tag?
The jsp taglib directive.
What are the 3 tags used in JSP bean development?
jsp:useBean jsp:setProperty jsp:getProperty
How to disable session in JSP?
<%@ page session="false" %>
What are various attributes Of page directive?
Page directive contains the following 13 attributes.
language extends import session isThreadSafe info errorPage isErrorpage contentType isELIgnored buffer autoFlush isScriptingEnabled
What is a include directive?
The include directive is used to includes a file during the translation phase. This directive tells the container to merge the content of other external files with the current JSP during the translation phase. You may code include directives anywhere in your JSP page.
The general usage form of this directive is as follows: ? 1
<%@ include file="relative url" >
What is a taglib directive?
The taglib directive follows the following syntax: ? 1
<%@ taglib uri="uri" prefix="prefixOfTag">
uri : attribute value resolves to a location the container understands
prefix : attribute informs a container what bits of markup are custom actions.
The taglib directive follows the following syntax: ? 1
<%@ taglib uri="uri" prefix="prefixOfTag" >
what is the function of action?
This action lets you insert files into the page being generated. The syntax looks like this: ? 1
Where page is the the relative URL of the page to be included.
Flush is the boolean attribute the determines whether the included resource has its buffer flushed before it is included.
What is Action?
The plugin action is used to insert Java components into a JSP page. It determines the type of browser and inserts the ? 1
or
tags as needed.
If the needed plugin is not present, it downloads the plugin and then executes the Java component. The Java component can be either an Applet or a JavaBean.
What is difference between GET and POST method in HTTP protocol?
The GET method sends the encoded user information appended to the page request. The page and the encoded information are separated by the ? Character.
The POST method packages the information in exactly the same way as GET methods, but instead of sending it as a text string after a ? in the URL it sends it as a separate message. This message comes to the backend program in the form of the standard input which you can parse and use for your processing.
0 notes
Link
The best course to learn Java, OOP, JDBC, Servlets, JSPs, Java EE, Web Services, JSF, EJB, JPA, Struts, Spring,Hibernate
What you’ll learn
Create Web and Enterprise Java applications with real skills to get opportunities in the market as a professional Java programmer
Master the fundamentals of Java, connection to database, to the creation of Web applications with Servlets, JPS’s, HTML, CSS and JavaScript,. At this level it is considered in the labor market as Java Junior programmer
Master Java Enterprise technologies (Java EE or Java2EE before) such as EJB’s, JPA, Web Services, JSF, PrimeFaces, among several others. The labor market is known as Java Senior Programmers (Java Sr) and is among the highest ranks in Java programmers.
At the end they will dominate all the previous topics, since each level relies on the previous one to obtain the levels that the Java labor market needs.
Set the bases to begin your certification preparation as a Java programmer
Requirements
The course starts from scratch, and reaches intermediate and advanced Java language levels. All in the same course.
No prior knowledge is required, only basic PC management
Description
+330 PDF (eBooks), + 22,500 students, + 300 reviews of very satisfied students, and the best HIGH PRIORITY Support for any doubt of your course, only for students enrolled in the course. YOU WILL NEVER BE ALONE. “The Java University is the best course to learn Java and now in English.”
The Java University course is already a Best Seller at UDEMY Spanish [Universidad Java], and NOW the Java University is also published in English. All the videos are in English and include subtitles (generated manually not automatically). And every Video has it’s corresponding PDF or eBook. So you can study Online or Offline. This is just great!!!
This course is a specialization in Java technology. We will start from the Java Fundamentals, and take you step by step to become a Java expert in record time and so you can create Web and Enterprise Java applications, including topics and technologies such as Java Basics, Object Oriented Programming (OOP), Design Patterns, JDBC, HTML, CSS and JavaScript, Servlets and JSPs, Struts Framework, Hibernate Framework, Spring Framework, Java Enterprise (Java EE now Jakarta EE), including EJB’s, JPA, Web Services, Security and much much more.
With all the above, you will have the bases to prepare several certifications as a Java programmer, in addition to acquiring the knowledge to be able to apply to several job vacancies to start working as a Java programmer in record time.
Java University has spent years in the market training Java professionals ready to enter the Java labor market. And now the Java University is at UDEMY to provide the full array of Java tools and technologies you need for the real world and professional Java.
This is the best Online course to learn Java. The content is divided into perfectly structured levels, each level supported by the previous one, with the aim of adding Java knowledge incrementally and so you can focus on mastering the issues little by little and gradually. So ensure the success of your Java training.
We will offer support of any doubt of the didactic material included in this Java specialization.
To make matters worse, we manage a new teaching methodology that we have called Speed Learning. This methodology consists of concise videos that go directly to the point to be studied, complemented by eBooks with explanations and step-by-step images (which you can print, or search for any text you need, or use for your offline study), since As we know we can not do text search within video. In addition, our methodology includes perfectly structured and very didactic exercises that will allow you to accelerate your eLearning learning. No loss of time in videos where you have to watch the instructor codify an exercise, too much theory, little practice or anything like that. Our Speed Learning methodology guarantees that in the shortest possible time you will acquire the necessary knowledge for the Java professional and working world.
The Java University includes the following topics of study in Java technology and related technologies:
Level 1. Java Fundamentals
Lesson 1 – Starting with Java Technology
The amazing world of Java programming What is Java technology (from a practical approach) Our first Java program from scratch
Lesson 2 – Variables and Operators in Java
Use of Variables in Java and what we use them for Types of Data in Java and how they are classified Management and Classification of operators in Java
Lesson 3 – Control statements in Java
Using the if-else structure and where to use it Handling the switch structure and when applying it
Lesson 4 – Handling Cycles in Java
Use of the for cycle and its use Using the while loop and how to apply it Use of the do-while cycle and when to use it
Lesson 5 – Object Oriented Programming
Introduction to Object Oriented Programming (OOP) Handling Classes in Java Use of Objects in Java
Lesson 6 – Functions in Java
Declaration of Methods or Functions in Java Use and call of functions in Java
Lesson 7 – Data Management in Java
Using Arrays in Java Management of Matrices in Java
Lesson 8 – Inheritance in Java
Inheritance Management in Java Use of superclasses and subclasses in Java Final Level Laboratory
Final Exercise where everything learned in this Level is included
Level 2. Java Programming
Lesson 1 – Polymorphism in Java
What is polymorphism and its application Overwriting in Java and its use
Lesson 2 – Advanced Object Management in Java
Conversion of Objects (cast) Identifying the type of object with the instanceof operator The importance and use of the operator this
Lesson 3 – Handling Code Blocks in Java
Scope of Variables (Scope) Use of static and non-static blocks
Lesson 4 – Use of Abstract Classes and Interfaces in Java
Differences between Abstract Classes and Interfaces Declaration and use of Abstract Classes Handling Interfaces in Java and when to use them
Lesson 5 – Handling Exceptions in Java
Processing exceptions in Java Use of try-catch and propagation of Exceptions
Module 6 – Manage Collections in Java
Using collections in Java Management of List, Set and Map and the application of each structure
Module 7 – Handling Files in Java
Handling and using files in Java Streams management in Java and its uses Final Level Laboratory
Final Exercise where everything learned in this level is applied
Level 3. Connection to Databases with JDBC
Lesson 1 – Starting with JDBC (Java Database Connectivity)
The need for a database Installing MySql and Oracle Download drivers (drivers) to connect to the base
Lesson 2 – Connecting to the Database
Steps to connect to a relational database JDBC code to connect to the database
Lesson 3 – Select Sentence
Steps to execute the SQL Select statement with JDBC Using the select statement to read the information in the database Lesson 4 – Manipulating Data with JDBC
Steps to execute the insert, update and delete statements Use of insert, update and delete statements to manipulate information Separation of functions select, insert, update and delete with JDBC
Lesson 5 – Metadata with JDBC
Knowing the structure of tables with JDBC The importance of using metadata in JDBC
Lesson 6 – Oracle, Store Procedures and Functions
Java JDBC with Oracle Execution of Oracle Store Procedures with JDBC Execution of Oracle functions with JDBC
Lesson 7 – Multilayer Architecture
Structuring our JDBC code Creating the data layer in a Multilayer Architectures
Lesson 8 – Design Patterns
DAO Design Pattern (Data Access Object) Design Pattern DTO (Data Transfer Object) or VO (Value Object) Final Laboratory with the integration of everything seen in this Level
Level 4 – HTML, CSS and JavaScript
Lesson 1 – Introduction to HTML
We will study an introduction to HTML technology Understanding the role of HTML in the world of Web applications
Lesson 2 – Components in HTML
The HTML components and how a Web page is structured Use of Text components, Fonts, Preformat and more in HTML
Lesson 3 – Introduction to CSS
Introduction to CSS Style Sheets The most important aspects to consider when using CSS Use of classes and identifiers in CSS
Lesson 4 – Forms in HTML
Elements to consider when creating HTML Forms Components for the creation of HTML Forms
Lesson 5 – Introduction to JavaScript
What is JavaScript and how to apply it in our HTML pages Basic elements of the JavaScript language
Lesson 6 – HTML Forms Validation
Integration of HTML and JavaScript Forms Validation of Forms with JavaScript
Level 5 – Servlets and JSPs
Lesson 1 – Introduction to Web Technology with Java
The amazing world of Web technology with Java The revolution of Web applications and how to take advantage of it The Tomcat application server and how to use it
Lesson 2 – Basic Concepts of Servlets
No mysteries: what is the technology of Servlets Elements and life cycle of a Servlet
Lesson 3 – Handling Sessions with Servlets
Implementation of the concept of Sessions with Servlets We will learn the use of the HttpSession object We will implement a shopping cart Web
Lesson 4 – Basic Concepts of the JSPs
We will study how to create dynamic Web pages with JSPs We will learn the fundamental elements of the JSPs
Lesson 5 – Advanced Concepts of Servlets and JSPs
We will see how to create a Web application integrating Servlets and JSPs Data processing with Servlets and information deployment with JSPs
Lesson 6 – JSTL and EL (Expression Language) in JSPs
We will understand the JSTL tags to facilitate the use of JSPs We will see the power of EL (Expression Language) in the JSPs
Lesson 7 – MVC Design Pattern (Model View Controller)
We will study a multilayer architecture of the real world with Servlets and JSPs We will apply the MVC design pattern with Servlets and JSPs
Lesson 8 – SMS Application (Student Management System)
Integration of the first 5 levels in a final project (SMS) Analysis, Design and Development of the SMS application
This level allows them to get employment from scholarship or Java Junior programmer
Level 6 – Struts Framework
Lesson 1 – Introduction to Struts Framework
What is a Struts Framework? Installation of Course Tools
Lesson 2 – Hello World with Struts
Creation of the Web project with Struts Framework Hello World with Struts.
Lesson 3 – Actions Management with Struts
Actions with Struts Exercise Actions with Struts More Actions with Struts
Lesson 4 – Handling Forms with Struts
FormBeans with Struts Exercise with FormBeans Filling Forms with Struts
Lesson 5 – Advanced Actions with Struts
Advanced Forms with Struts Exercise Advanced Forms with Struts
Lesson 6 – Internationalization with Struts
Internationalization Management with Struts Exercise management of messages with Struts Internationalization management exercise with Struts
Lesson 7 – Handling Exceptions with Struts
Management of Exceptions with Struts Exercise Handling Exceptions with Struts
Lesson 8 – Manual Validation with Struts
Manual Validation with Struts Exercise Manual Validation with Struts
Lesson 9 – Automatic Validation with Struts
Automatic Validation with Struts Automatic Validation Exercise
Lesson 10 – Handling Tiles (Templates) with Struts
Use of Tiles (Templates) with Struts Exercise Templates with Struts Final Laboratory Conclusion of the Course with Struts
Level 7 – Hibernate Framework and JPA (JavaPersistence API)
Lesson 1 – Introduction to Hibernate Framework
What is an ORM – Object Relational Mapping? How Hibernate helps me in a multilayer business design How to be much more productive in the data layer with Hibernate
Lesson 2 – Configuring Hibernate
We will review the DAO and DTO Design Patterns We will implement the basic operations with Hibernate. We will create a Web application with JSPs, Servlets and Hibernate.
Lesson 3 – Handling Relationships with Hibernate
We will study the types of Associations in Hibernate We will see the one-one, one-many, and many-many relationships We will study the concept of Entity Classes offered by Hibernate
Lesson 4 – Life Cycle in Entity Objects
We will study the concept of the Life Cycle in Entity Objects We will learn the concept of Persistence and Persistence in Cascade
Lesson 5 – Queries with HQL
We will learn the HQL language (Hibernate Query Language) We will study the concept of JOINS in HQL We will analyze the concept of Lazy Loading and Fetch in HIbernate
Lesson 6 – Criteria API Queries
We will study the Criteria API and how to apply it in Hibernate We will analyze in which cases to apply HQL or the Criteria API
Lesson 7 – Query by Example
We will learn to apply Criteria Join and Fetch We will use Query by Example to create advanced queries
Lesson 8 – SGA System with Hibernate
We will build the SGA system with Hibernate We will build the data layer using Hibernate We will create advanced queries with Hibernate We will apply everything learned in this Level
Level 8 – Spring Framework
Lesson 1 – Introduction to Spring
What is Spring and its importance in the Java EE world? Basic concepts of Spring and its modules Multilayer architectures using Spring Framework
Lesson 2 – Spring Configuration
How Spring applies cohesion and coupling What is the Spring Factory and how to configure it?
Lesson 3 – Dependency Injection
Dependency Injection Management with Spring Relationship between classes and their use with Spring Types of Dependency Injections with Spring Using Annotations with Spring
Lesson 4 – Aspect Oriented Programming
Introduction to Aspect Oriented Programming (AOP) Use of AOP and Spring Concepts of Pointcuts in AOP and Spring Around, Introductions and Annotations with AOP
Lesson 5 – Spring and JDBC
Introduction to Spring with JDBC Using Templates with Spring JDBC General configuration of Spring JDBC Configuring a DataSource in Spring Queries with Spring JDBC Using RowMapper with Spring JDBC
Lesson 6 – Handling Transactions with Spring
Introduction to Spring with JDBC Definition of TransactionManager in Spring Attributes of a Transaction Propagation of a Transaction in Spring Transaction Settings in Spring
Lesson 7 – JSF Integration – Spring – JPA
Integration of Spring and JPA Steps to integrate JSF, Spring and JPA Conclusion of the Level
Level 9 – Java Server Faces
Lesson 1 – Introduction to JavaServer Faces
What is JSF and its role in Java EE Basic concepts of JSF and MVC Hello World with JSF
Lesson 2 – ManagedBeans in JSF
ManagedBeans concept in JSF Using ModelManagedBeans in JSF Expression Language (EL) in JSF Colect of BackingBeans in JSF Scope Management (Scopes) in JSF
Lesson 3 – Navigation Rules in JSF
Navigation Rules in JSF Life Cycle in JSF
Lesson 4 – Validators in JSF
Management of Validators in JSF Use of Converters in JSF Message Management and Internationalization in JSF
Lesson 5 – Event Management in JSF
Using the Value Change Listener Handling ActionListener and ActionEvent in JSF Use of standard library and SelectItems in JSF
Lesson 6 – Handling Facelets
The evolution of JSP and the use of Facelets The use and importance of Faceltes in JSF
Lesson 7 – Integration of Java EE Services
The role of JSF, EJB and JPA Exercise where everything seen in is integrated
Level 10 – Java Enterprise Edition (Jakarta EE)
Lesson 1 – Introduction to Java EE
Introduction to the Java Enterprise world (Java EE) Java EE Technology Stack Multilayer architecture in Java EE Installation of the Tools (Eclipse, MySql) Installation of the Glassfish Application Server Use of Maven and JavaEE Hello World with JavaEE
Lesson 2 – Enterprise Java Beans (EJB)
Introduction to EJBs Types and Configuration of an EJB Injection of Dependencies in Java EE Packaging and Business Containers
Lesson 3 – Introduction to the Java Persistence API (JPA)
Introduction to the Java Persistence API (JPA) Understanding of the classes of Entity in JPA Operation of EntityManager and Persistence Unit Use of JUnit and JPA
Lesson 4 – Consultations with JPA
Life Cycle in JPA Types of Relations in JPA JPQL queries in JPA Using the Criteria API in JPA Transaction Management in JPA
Lesson 5 – Role of Servlets and JSPs
Role of Servlets and JSPs in Java EE Role of JSPs in Java EE Servlets and EJB integration in Java EE
Lesson 6 – Role of JSF
Role of JSF in Java EE Ajax at JSF PrimeFaces and JSF JSF, PrimeFaces, AJAX, EJB and JPA integration
Lesson 7 – WebServices and JavaEE
Introduction to Web Services Types of JAX-WS and JAX-RS Web Services What is a WSDL Document Use of XML and XSD Documents (XML Scheme) Handling the JAXB API Web Services Generation Strategies Deployment of Web Services Creation of the Web Service Client
Lesson 8 – REST Web Services
Introduction to REST Web Services Analysis of HTTP Requests JAX-RS API annotations Integration of EJB and JAX-RS Creating a REST Client Document WADL and XSD of the REST Web Service Deploying a REST Web Service Creation of REST Web Service Client
Lesson 9 – Java EE security
Introduction to Java EE Security Authentication and Authorization in Java EE Security in the Web Layer in Java EE Security in EJB Layer in Java EE Client Authentication in Java EE Web Client Authentication SOAP Client Authentication and REST Web Service Final Exercise with the integration of everything learned
Remember, your satisfaction is guaranteed or your money back.
Greetings and see you from the other side. You’ll be a Java Expert in record time!!!
Eng. Ubaldo Acosta
Passion for Java technology
Founder of Global Mentoring and Java University
Who this course is for:
Anyone who is interested in becoming a professional Java programmer
Anyone interested in learning Java from the basics
Anyone interested in learning to develop business applications with Java EE, including technologies such as JSF, PrimeFaces, EJB’s, JPA, Web Services and Java EE Security, among many other topics
Anyone interested in becoming a Java Junior or Java Senior specialist depending on the level studied, but at the end they will have the level of a Java Senior programmer.
The course can be studied by anyone interested in Java, from novice, intermediate or advanced programmers, since the Java University covers all levels
Anyone interested in becoming a Java professional programmer
Created by Global Mentoring Last updated 12/2018 English English
Size: 5.47 GB
Download Now
https://ift.tt/2OIYraA.
The post Java University: From Beginner to Expert in Java [10 in 1]! appeared first on Free Course Lab.
0 notes
Text
WHAT IS JSESSIONID IN JAVA? WHEN DOES JSESSIONID GETS CREATED ?
JSESSION id is a cookie which is used to manage session in Java web application. JSESSIONID is created by Web Container whenever a new session is created.
In Java J2EE application container is responsible for Session management and by default uses Cookie. When a user first time access your web application, session is created based on whether its accessing HTML, JSP or Servlet. if user request is served by Servlet than session is created by calling request.getSession(true) method. it accepts a boolean parameter which instruct to create session if its not already existed.
If you call request.getSession(false) then it will either return null if no session is associated with this user or return the associated HttpSession object. If HttpRequest is for JSP page than Container automatically creates a new Session with JSESSIONID if this feature is not disabled explicitly by using page directive %@ page session=”false” %>.
Once Session is created Container sends JSESSIONID cookie into response to the client.
http://conceptlearningcentre.com/index.php/2016/10/25/jsessionid-java-jsessionid-gets-created/
0 notes
Text
Multi-project Java build
Multi-project Java build
Now let’s look at a typical multi-project build. Below is the layout for the project:
Example: Multi-project build - hierarchical layout
Build layout
multiproject/ api/ services/webservice/ shared/ services/shared/
Note: The code for this example can be found at samples/java/multiproject in the ‘-all’ distribution of Gradle.
Here we have four projects. Project api produces a JAR file which is shipped to the client to provide them a Java client for your XML webservice. Project webservice is a webapp which returns XML. Project shared contains code used both by api and webservice. Project services/shared has code that depends on the shared project.
Defining a multi-project build
To define a multi-project build, you need to create a settings file. The settings file lives in the root directory of the source tree, and specifies which projects to include in the build. It must be called settings.gradle. For this example, we are using a simple hierarchical layout. Here is the corresponding settings file:
Example: Multi-project build - settings.gradle file
settings.gradle
include "shared", "api", "services:webservice", "services:shared"
You can find out more about the settings file in Authoring Multi-Project Builds.
Common configuration
For most multi-project builds, there is some configuration which is common to all projects. In our sample, we will define this common configuration in the root project, using a technique called configuration injection. Here, the root project is like a container and the subprojects method iterates over the elements of this container - the projects in this instance - and injects the specified configuration. This way we can easily define the manifest content for all archives, and some common dependencies:
Example: Multi-project build - common configuration
build.gradle
subprojects { apply plugin: 'java' apply plugin: 'eclipse-wtp' repositories { mavenCentral() } dependencies { testCompile 'junit:junit:4.12' } version = '1.0' jar { manifest.attributes provider: 'gradle' } }
Notice that our sample applies the Java plugin to each subproject. This means the tasks and configuration properties we have seen in the previous section are available in each subproject. So, you can compile, test, and JAR all the projects by running gradle buildfrom the root project directory.
Also note that these plugins are only applied within the subprojects section, not at the root level, so the root build will not expect to find Java source files in the root project, only in the subprojects.
Dependencies between projects
You can add dependencies between projects in the same build, so that, for example, the JAR file of one project is used to compile another project. In the api build file we will add a dependency on the shared project. Due to this dependency, Gradle will ensure that project shared always gets built before project api.
Example: Multi-project build - dependencies between projects
api/build.gradle
dependencies { compile project(':shared') }
See the section called ��Disabling the build of dependency projects” for how to disable this functionality.
Creating a distribution
We also add a distribution, that gets shipped to the client:
Example: Multi-project build - distribution file
api/build.gradle
task dist(type: Zip) { dependsOn spiJar from 'src/dist' into('libs') { from spiJar.archivePath from configurations.runtime } } artifacts { archives dist }
Program to print alphabets in java. Java Arithmetic Operators Example. Armstrong number program in java. Even odd program in java. Factorial program in java . Factorial program recursion in java. Fibonacci series program in java. Palindrome number program in java. Prime number program in java. Java swap two numbers without using third variable. Swap numbers program in java. Reverse number program in java. Calculate circle area using java. Calculate circle perimeter in java. Calculate rectangle area using java. Calculate rectangle perimeter java. Leap year java program code. List Even Numbers in Java. List Odd Numbers in Java. Floyd triangle in java example. Generate pyramid for a given number. Generate pyramid triangle in java. Servlets tutorial. Servlet overview. Life cycle of a servlet. Servlet interface. GenericServlet class. HttpServlet class. web.xml file. welcome-file-list. load-on-startup. RequestDispacher interface. sendRedirect. Init parameters. Context parameters. Annotation example. Session management. Cookie in servlet. Hidden field. URL rewriting. HttpSession. Servlet filter. FilterConfig interface. JSP tutorial. JSP overview. JSP Hello World. JSP Scriptlet tag. JSP Declaration tag. JSP Expression tag. JSP comment tag. JSP directives. JSP implicit objects. JSP action tags. Exception handling. Expression Language. JSTL. JSTL Core Tags. JSTL Formatting Tags. JSTL Functions. Custom tags. Custom tag with attributes. Struts tutorial. Struts 2 overview. Struts 2 Architecture. Configuration Files. Action in struts 2. Hello World example. Multi-configuration file. OGNL. Value Stack. Interceptors. execAndWait interceptor. Custom interceptor. Result type. Redirect result type. Validation framework. Built-in validators. Zero Configuration by convention approach. Zero Configuration by annotation approach. DispatchAction Functionality. Dynamic method invocation. UI tags. Control tags. Data tags. Tiles integration. Spring tutorial. Spring framework. Spring architecture. Spring ioc container. Spring bean. Spring bean scopes. Spring bean life cycle. Spring callback methods. Spring hello world. Spring bean definition inheritance. Spring bean definition template. Spring dependency injection. Spring constructor based injection. Constructor injection type ambiguities. Setter based dependency injection.
0 notes
Text
Accessing HTTP Session in WebSocket endpoint
Accessing HTTP Session in WebSocket endpoint
It’s possible to obtain a reference to the HttpSession within a WebSocket application using a custom implementation of ServerEndpointConfig.Configurator
Here is an example application on Github
Steps…
Override the modifyHandshakeRequest method
call the getHttpSession method on the HandshakeRequest object which is passed into the method by the WebSocket runtime
store it– one possible option is to…
View On WordPress
0 notes