<HTML> <HEAD> <TITLE>Using Abstract Classes</TITLE> </HEAD> <BODY> <H1>Using Abstract Classes</H1> <%! javax.servlet.jsp.JspWriter localOut; abstract class a { abstract String getText() throws java.io.IOException; public void printem() throws java.io.IOException { localOut.println(getText()); } } class b extends a { String getText() throws java.io.IOException { return "Hello from JSP!"; } } %> <% localOut = out; b bObject = new b(); bObject.printem(); %> </BODY> </HTML>
Showing posts with label learn advance java. Show all posts
Showing posts with label learn advance java. Show all posts
Saturday, 17 December 2011
JSP Examples Tutorial - Using Abstract Classes in JSP
Thursday, 15 December 2011
Initializing a Servlet
After the Web container loads and instantiates the servlet class and before it delivers requests from clients, the Web container initializes the servlet. You can customize this process to allow the servlet to read persistent configuration data, initialize resources, and perform any other one-time activities by overriding the
init method of the Servlet interface. A servlet that cannot complete its initialization process should throw UnavailableException.All the servlets that access the bookstore database (
BookStoreServlet, CatalogServlet, BookDetailsServlet, and ShowCartServlet) initialize a variable in their init method that points to the database helper object created by the Web context listener:public class CatalogServlet extends HttpServlet {
private BookDB bookDB;
public void init() throws ServletException {
bookDB = (BookDB)getServletContext().
getAttribute("bookDB");
if (bookDB == null) throw new
UnavailableException("Couldn't get database.");
}
}
Subscribe to:
Posts (Atom)