JSP reference5 kinds of things:Scriplet, Expressions (returning a string), declarations, actions, directives.Scriptlets:<% code here %>or <jsp:scriptlet> code here </jsp:scriptlet> Expressions:<%= var_name %>or <% out.print(var_name) %> or <jsp:expression>var_name</jsp:expression> Declarations:<%! var_name=constant (no output) %>or <jsp:declaration>delcarative code</jsp:declaration> Actions:<jsp:useBean id="var_name" class="sub_classpath"scope="page|request|session|application" type="class" beanName="var_name"> <jsp:setProperty|getProperty> </jsp:useBean> <jsp:include> (inserts text "as is" AFTER the parsing) or <%@ include file="filename" %> (inserts code into the page BEFORE parsing) or <jsp:include page="somepage.htm" flush="true" /> <jsp:forward page="somepage.htm"/> <jsp:plugin type="applet" code="x.class" codebase="/java" vspace="0" hspace="0" width="60" height="80" jrevision="1.2" iepluginurl="" nspluginurl=""> <jsp:param name="z" value="dummy"/> <jsp:fallback>Unable to initialize java...</jsp:fallback> </jsp:plugin> Directives:<%@ directive_name %>or <jsp:directive.directive_name/> <%@page attribute="value" import="name" language="java" <jsp:directive.include file="name"/> (affects the rest of the page, but cannot do dynamic includes) (Action allows dynamic includes (<%=foo%>) but cannot affect the rest of the page) <%@ taglib uri="http://www...jar" prefix="my" %> comments:<%-- comment --%><!-- comment --> <% code... //comment %> Other:All code is in Java (obviously).To precompile a script enter the URL: my_file.jsp?jsp_precompile="true" All <%! ... %> tags are persistent across threads isThreadSafe="false" turns off multithreading. synchronized(object){statements} assures that the statements are single threaded. <%@page errorPage="errors.htm" %> out.print("hello"); is the default form for JSP void jspInit() and void jspDestroy() are the built-in start and stop procedures. The proper form of JSP is XML compliant. Get details on custom tags if interested... Request:getParameter(parameter);getServerName(); getRequestURI(); getQueryString(); getReader(); getInputStream(); getMethod(); String getAttribute(String); Enumeration getAttributeNames(); getParameterNames(); getParameterValues(); cookie[] getCookie(); getHeader("cookie"); new Cookie (String name, String value); void cookie.setMaxAge(int expire); void cookie.setSecure(boolean flag); void cookie.setDomain(String pattern); void cookie.setPath(String URI); Response:Void addCookie(Cookie cookie);void setContentType(String type); addHeader(String name, String value) setHeader(...); addIntHeader(String name, int value); setIntHeader(...); addDateHeader(String name, long date); setDateHeader(...); (add adds a new header line, set replaces the header line) sendError(int code, String Msg); (HTTP response codes) void sendRedirect("http://..."); Session:putValue(String key, object value);getValue(String key); removeValue(String key); String[] getValueNames(); getMaxInteractiveInterval(); setMaxInteractiveInterval(int Seconds); long getCreationTime(); long getlastAccessedTime(); invalidate(); boolean isnew(); getID(); Application:getServerInfo();getRealPath(request.getRequestURI()); log(); JavaBean design:
Enterprise Java Beans are more restrictive: There are two kinds - session beans and entity beans. Session beans are transient with only onw client each. Entity beans represent persistent storage (possibly from a database). JDBC:Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");DriverManager.RegisterDriver(new Oracle.jdbc.driver.OracleDriver()); connection conn=DriverManager.getConnection(URL, login, password); statement st=conn.CreateStatement(); resultSet rset st.executeQuery(SQL); int returnValue=st.executeUpdate(otherSQL); st.close; conn.close; |