JavaBeanEJB的区别

JavaBean是可视的或者是不可视的,不用部署,EJB是不可视的,需要部署到服务器中。

JavaBean部署在应用程序中, EJB是部署在容器中,可以是有状态或者是无状态的,声明式事务。

JavaBean的属性和方法是普通的,EJB是需要遵守规范,是需要通过标准的描述符来定义的。

JavaBean是基于事件驱动的,EJB中只有消息驱动Bean是基于事件的

注意:jsp:useBean动作,用表单为Bean的属性赋值时,也就是jsp:setProperty动作直接收请求中表单的信息为使用的Bean的属性进行赋值,也就是说jsp:useBean和jsp:setProperty不能够出现在为这个Bean的属性赋值的form表单的页面上。

JSP的异常处理

<%@page errorPage="xxx.jsp"%> 指定本页面出现异常后要转到的页面
<%@page iserrorPage="true"%> 见本页面指定为异常处理页面,也就是其他出异常的页面可以指定本页面为要转到的异常处理页面。
处理异常
运行时异常
1) 一个程序运行时重获的错误;
2) 能被一固有的异常对象引用所使用;
3) 可以利用异常引用创建或产生一个JSP页面显示异常信息给用户。
创建一个异常跟踪方案
1) 在每一个JSP页面,包含要创建的异常页面名称;   
<%@page import="numberguess.NumberGuessBean" errorPage="error.jsp"%>
2) 创建一个异常页面;   
<%@page isErrorPage="true"%>
JSP页面中的异常处理
1) <%=exception.toString()%>        打印异常名称;
2) <%exception.printStackTrace();%> 打印当前错误流中所有错误的列表;
3) <%=exception.getMessage()%> 打印错误的详细描述信息
JSP中异常页面的部署描述
<error-page>
       <error-code>404</error-code>
       <location>notFound.html</location>
</error-page>
<error-page>
       <exception-type>java.lang.NumberFormatException</exception-page>
<location>error.jsp</location>
</error-page>
JSP隐含内置对象
JSP中隐含内置对象
名称         类型                                     注释和范围
request      javax.servlet.http.HttpServletRequest                      request
response     javax.servlet.http.HttpServletResponse                    response
page         javax.lang.Object                                   page
Exception    java.lang.Throwable                                  page
pageContext  javax.servlet.jsp.PageContext                             page
session      javax.servlet.http.HttpSession                           session
application  javax.servlet.ServletContext                        ServletContext
out          javax.servlet.jsp.JspWriter                      OutputStream
config       javax.servlet.ServletConfig                      ServletConfig
 
内置对象request(HttpServletRequest)
1)封装了来自客户端的请求:    
2)方法:
Parameter related methods:
     +getParameterNames():Enumberation 返回form中对象名称的枚举;          
       +getParameter(String name):String返回指定名称的对象值; 
+getParameterValues(String name) :String[ ] 返回指定名称的对象值数组;
+getParameterMap():Map
Attribute related methods: 
       +setAttribute(String name,Object value) :void  设置属性
       +getAttribute(String name) :Oject  返回属性值;
       +removeAttribute(String name) :void
       +getAttributeNames():Enumberation  返回属性名称
URL related methods:
       +getContextPath():String
       +getServletPath():String
       +getPathInfo():String
State related methods:
+getCookies():Cooie[ ] 取得Cookie数组;
+getSession():HttpSession
+getSession(Boolean create) :HttpSession
 
内置对象response(HttpServletResponse)
+getWriter():PrintWriter
+addCookie(Cookie c) :void
+encodeURL(String URL) :String
+sendRedirect(String URL) :void
+sendError(int errorCode) :void
 
内置对象session(HttpSession)
       +setAttribute(String name,Object value) :void  设置属性
       +getAttribute(String name) :Oject  返回属性值;
       +removeAttribute(String name) :void
       +getAttributeNames():Enumberation  返回属性名称
Other motheds:
+seMaxInactiveInterval(int seconds) :void
 Invalidate():void
 
内置对象pageContext(PageContext)
       +setAttribute(String name,Object value) :void  设置属性
       +getAttribute(String name) :Oject  返回属性值;
       +removeAttribute(String name) :void
       +getAttributeNames():Enumberation  返回属性名称
+findAttribute(String name) :Object
Other motheds:
+getRequest():HttpServletRequest
+getSession():HttpSession
+getServletContext():ServletContext
+getOut():JspWriter
 
内置对象application(ServletContext)
       +setAttribute(String name,Object value) :void  设置属性
       +getAttribute(String name) :Oject  返回属性值;
       +removeAttribute(String name) :void
       +getAttributeNames():Enumberation  返回属性名称
Other methods:
+getRequstDispather(String URL):RequestDispather 
+getInitParameter(String name) :String
内置对象out
1)JSPWriter的一个实例, 用于发送响应给客户端    
2)方法:
   print(String)/println(String) 用于向页面输出          
   print(int)/println(int)          
   flush() 刷新out对象的缓存
内置对象exception
1) 用于异常对象的异常实例;    
2) 异常页面在page指令中存在属性 isErrorPage="true";    
3) 方法:
   getMessage()/printStackTrace()/toString() 
内置对象session
1) HttpSession的一个实例, 用于来维护session的状态    
2) 方法:
   getAttribute(String name)/setAttribute(String name) 
   取得设置的属性的对应资源/设置属性的对应资源             
   removeAttribute(String name)  删除属性和队应资源             
   getAttributeNames() 
   返回值是一个迭代器,可以获得session中设置的属性的名字也就是在set时使用的与资源对应的那个名字
内置对象application
1) ServletContext一个实例,用来维护application的状态    
2) 方法:   
   getAttribute()/setAttribute() 和session以及request中的那一对设置属性及其对应资源的方法    
   getInitParameter()    获得初始化参数                
   getServletInfo()  获得Servlet的信息

3) application的作用域比session大得多,一个session和一个client联系, 而application保持了用于所有客户端的状态。

注意:如果要保存的数据量比较大时,就要使用生命周期比较短的request对象,page对象只在本页面中有效,也就是会再翻译后的service