Skip to main content

Posts

JSP tutorial part 15:Invoking a JSP Page from a Servlet

Invoking a JSP Page from a Servlet You can invoke a JSP page from a servlet through functionality of the standard javax.servlet.RequestDispatcher interface. Complete the following steps in your code to use this mechanism: ·          Get a servlet context instance from the servlet instance: ServletContext sc = this.getServletContext(); ·          Get a request dispatcher from the servlet context instance, specifying the absolute path of the target JSP page as input to the getRequestDispatcher() method: RequestDispatcher rd = sc.getRequestDispatcher("/jsp/mypage.jsp"); ·          Invoke the include() or forward() methods of the request dispatcher, specifying the HTTP request and response objects as arguments. rd.include(request, response); or rd.forward(request, response); ·          The functionality of...

JSP tutorial part 14:Difference Between Include Directive and Include action

Difference Between Include Directive and Include action include Directive: — At JSP page translation time, the content of the file given in the include directive is ‘pasted’ as it is, in the place where the JSP include directive is used.  Then the source JSP page is converted into a java servlet class. The included file can be a static resource or a JSP page.  Generally JSP include directive is used to include header banners and footers.   — The source JSP page gets compiled only if that page has changed.   — If there is a change in the included JSP file, the source JSP file will not be compiled and therefore the modification will not get reflected in the output. Include Action: <jsp:include page= "index.jsp“> The jsp:include action element is like a function call. At runtime, the included file will be ‘executed’ and the result content will be included with the source JSP page. When the included JSP page is called, both the reque...

JSP tutorial part 13: Example Include action Tag dynamically

Another Example Include action Tag dynamically Header2.jsp <%@ page language=”java” contentType=”text/html; charset=ISO-8859-1” pageEncoding=”ISO-8859-1”%> <!DOCTYPE html PUBLIC “-/W3C//DTD HTML 4.01 Transitional//EN” “ http://www.w3.org/TR/html4/loose.dtd ”> <html> <head> <meeta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1”> <title>Header 2 Page</title> </head> <body> <table width=100%” border=’1’> <tr> <td><%=request.getParameter(“variable 1”) %></td> <td><%=request.getParameter(“variable 2”) %></td> <td><%=request.getParameter(“variable 3”) %></td> <td><%=request.getParameter(“variable 4”) %></td> </tr> </table> </body> </html> When we use param tags, it is dynamic forward with having values.Static forward is a simple forward is a simple forward without having pa...

JSP tutorial part 12:Include action tag example

Include action tag example Page2.jsp <%@ page language=”java” contentType=”text/html; charset=ISO-8859-1” pageEncoding=”ISO-8859-1”%> <!DOCTYPE html PUBLIC “-/W3C//DTD HTML 4.01 Transitional//EN” “ http://www.w3.org/TR/html4/loose.dtd ”> <html> <head> <meta http-equiv=”content-Type” content=”text/html;charset=ISO-8859-1”> <title>Insert title here</title> </head> <body> <% Int count=integer.parseInt(request.getParameter(“p_number”)); %> <table> <tr> <td>Number</td> </tr> <% for(int i=1;i<=count;i++){%> <tr> <td><%=i %></td> </tr><%} %> </table> </body> </html>

JSP tutorial part11: Include action tag

Include action tag The include action tag allows a static or dynamic resource such as HTML or JSP pages, specified by a URL, to be included in the current JSP while processing a request. General syntax of include action Tag: <jsp:include page=”{relativeURL |<%=expression%>}”> Include action in JSP is used to include resource in JSP file these resource can be either static or dynamic. • Elements of this action is processed at the time of the JSP page execution. • Here in case of the static resource contents are inserted into the calling JSP file and in case of dynamic resource first the included resource receives the request and executed and produces the result and then this result is included in the calling JSP file. Use the following syntax for a dynamic resource: <jsp:include page=”{relativeURL |<%=expression%>}”> <jsp:param name=”parameterName” value=” {parameterValue |<%=expression%>}”/> ·       ...

JSP tutorial part 10:JSP Action Tags

JSP Action Tags Working with JSP action Tags: — Action tags are a set of some basic tags, such as ◦ inserting other page resources ◦ forwarding the request to another page ◦ creating and locating the java bean instances ◦ setting and retrieving bean properties, in JSP pages. Note: Instead of using Java code, developers use special JSP action tags to either link to a Java Bean to set its properties, or get its properties. JSP Action Description jsp:include To include a resource at runtime, can be HTML, JSP or any other file jsp:useBean To get the java bean object from given scope or to create a new object of java bean. jsp:getProperty To get the property of a java bean, used with jsp:useBean action jsp:setProperty To set the property of a java bean object, used with jsp:useBean action. jsp:forward To forward the request to another resource. jsp:text To write templat...

Java tutorial

Java Binary Language: Developing the application in the binary language will take more time and very difficult also. The application which are developed under Binary language those are platform dependent. Platform:                 It is a combination of hardware and software, it will provide the environment. On top of that we can execute the programs.                 Execute programs means, installing software’s, typing some content on notepad. Platform Dependency:                 Whatever the application we developed and compiled under one operating system, that is not executing under different operating systems is called platform dependency. Whatever the application we developed under the binary language, that application is not executed in all the operatin...