含用表单的网页如果还是提交给该网页处理表单,或者是可能出错的网页由自已来处理。像这类的网页的的代码程序是如何执行的,顺序吗?还有对变量的初始化是只有一次吗?
看这个代码:
<html>
<head>where to go</head>
<%
String ad=request.getParameter("where");
if(ad!=null)
{
if(ad.equals("163"))response.sendRedirect("http://www.163.com");
else response.sendRedirect("http://www.yahoo.com.cn");
}
%>
<b>please select:</b><br>
<form action="1.jsp" method="GET">
<select name="where">
<option value="163" selected>go to 163
<option value="sohu">go to sohu
</select>
<input type="submit" value="go " name="submit">
</form>
</body>
</html>如果顺序执行的话,那么该网页一定会转到163的页面上,因为初始的where为163。做何解释?这样解释行不:正因为是顺序执行,所以REQUEST对象在执行到此处没有where这个属性值,所以得到NULL。到底是怎么样的请高手指教!
再看下面的例子:
<%@ page isErrorPage="true" errorPage="exception.jsp" contentType="text/html;charset=GBK" %>
<html>
<head>
  <title>exception对象</title>
</head>
<body >
<h2>发生异常</h2>
<%! boolean throwError=true;%>
<%
   if (throwError){
      throwError=false;
      throw new Exception("这里是测试用异常");
      }
%>
<b>错误描述:</b> <%= exception.getMessage() %>.<br/>
<%= exception.toString() %><p/>
<b>详细出错原因:</b><p/>
<pre>
<% exception.printStackTrace(new java.io.PrintWriter(out)); 
   throwError=true;
   %>
</pre>
</body>
</html>
这个网页也是由自已来处理的。假设前面所说的是顺序执行的。那以当该网页抛出异常后调用本页来重新执行<%! boolean throwError=true;%>
所以IF条件成立会继续抛出异常,这不成了一个死循环了/到底抛出异常后会不会再去执行<%! boolean throwError=true;%>成为关键问题《到底会不会,请高的给指点迷津/
这些问题困扰很久了,请高手指点:1:顺序执行?
                                2 :如何初始化(例2)