日期:2014-05-18  浏览次数:20668 次

处理jsp传参中异常
测试目的:
当页面a.jsp向页面b.jsp提交
b.jsp通过request.getParameter( "属性名 ")获得相应提交值
当a.jsp没有提交相应属性值时,通过Exception_other类来处理该异常
问题:报异常
-----------------   a.jsp   ---------------
<%@   page   language= "java "   import= "java.util.* "   pageEncoding= "UTF-8 "%>
<html>
    <head> </head>
    <body>
      <form   name= "form1 "   method= "post "   action= "b.jsp ">
      请输入用户姓名: <input   type= "text "   name= "username ">
      <input   type= "submit "   name= "Submit "   value= "提交 ">
      </form>
    </body>
</html>

----------------   b.jsp   -----------------
<%@   page   language= "java "   import= "java.util.*,com.cn.Exception_other "   pageEncoding= "UTF-8 "%>
<html>    
    <body>
        <%  
        String   username   =  
        Exception_other.operatGetMothod(request, "username ");
        %>
        <%=username%>
    </body>
</html>
-----------   com.cn.Exception_other   ----------
package   com.cn;

import   javax.servlet.http.HttpServletRequest;

public   class   Exception_other   {

private   static   String   getStr   =   " ";
public   static   String   operatGetMothod(HttpServletRequest   request,String   str){

try   {
getStr   =   request.getParameter(str);
if(getStr.equals(str)){
getStr   =   str;
}else{
getStr   =   " ";
}
}   catch   (Exception   e)   {
getStr   =   " ";
}
return   getStr;
}
}
========================所报错误========================
type   Exception   report

message  

description   The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

exception  

javax.servlet.ServletException:   javax/servlet/http/HttpServletRequest
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.b_jsp._jspService(b_jsp.java:63)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root   cause  

看看 disabled的有关问题