没使用try catch之前可以正确显示,因要设置权限问题要判断status所以加了try catch,而且在另一个页面加入了try后功能正确,现在编译时显示如下错误
"classes_list.jsp": while expected
"classes_list.jsp": '(' expected
"classes_list.jsp" 'try' without 'catch' or finally'代码如下:<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<%@taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@page contentType="text/html; charset=GBK"%>
<%@page import="java.util.Vector"%>
<%@page import="cn.com.es.bean.Classes"%>
<%
  String status = (String) session.getAttribute("STATUS");
  try {
%>
<jsp:include flush="true" page="../admin/admin_header.jsp"/>
<html:html>
  <head>
  <title>class_list</title>
  </head>
  <body bgcolor="#ffffff">
  <h1 align="center">班级信息</h1>
    status=
  <%session.getAttribute("STATUS");  %>
  <table align="center" border="1">
    <tr>
      <td>班级名</td>
      <td>状态</td>
      <td>班主任</td>
      <td>删除修改</td>
    </tr>
  <%
    if (request.getAttribute("CLASSES_LIST") == null) {
      Vector v = new Vector();
      request.setAttribute("CLASSES_LIST", v);
    }
    Vector v = (Vector) request.getAttribute("CLASSES_LIST");
    for (int i = 0; i < v.size(); i++) {
      Classes c = (Classes) v.get(i);
  %>
    <tr>
      <td><%= c.getName() %>      </td>
      <td><%= c.getState() %>      </td>
      <td><%= c.getManager() %>      </td>
      <td>
        <html:link href="">删除</html:link>
        <html:link href="">修改</html:link>
      </td>
    </tr>
  <%}  %>
  </table>
  <%request.removeAttribute("CLASSES_LIST");  %>
  <%
    //status为null跳转到错误页面
    } catch (NullPointerException ex) {
  %>
  <jsp:forward page="../error/err_url.jsp"/>
  <%}  %>
  </body>
</html:html>

解决方案 »

  1.   

    try{放到body之后,  <body bgcolor="#ffffff">
       <%try{%>
      <h1 align="center">班级信息</h1>
      

  2.   

    你在试试
    <%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
    <%@taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
    <%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
    <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@page contentType="text/html; charset=GBK"%>
    <%@page import="java.util.Vector"%>
    <%@page import="cn.com.es.bean.Classes"%>
    <html:html>
    <head>
      <title>class_list</title>
      </head>
      <body bgcolor="#ffffff">
      <h1 align="center">班级信息</h1>
    <%
      String status = (String) session.getAttribute("STATUS");
      try {
    %>
    <jsp:include flush="true" page="../admin/admin_header.jsp"/>
        status=
      <%session.getAttribute("STATUS");  %>
      <table align="center" border="1">
        <tr>
          <td>班级名</td>
          <td>状态</td>
          <td>班主任</td>
          <td>删除修改</td>
        </tr>
      <%
        if (request.getAttribute("CLASSES_LIST") == null) {
          Vector v = new Vector();
          request.setAttribute("CLASSES_LIST", v);
        }
        Vector v = (Vector) request.getAttribute("CLASSES_LIST");
        for (int i = 0; i < v.size(); i++) {
          Classes c = (Classes) v.get(i);
      %>
        <tr>
          <td><%= c.getName() %>      </td>
          <td><%= c.getState() %>      </td>
          <td><%= c.getManager() %>      </td>
          <td>
            <html:link href="">删除</html:link>
            <html:link href="">修改</html:link>
          </td>
        </tr>
      <%}  %>
      </table>
      <%request.removeAttribute("CLASSES_LIST");  %>
      <%
        //status为null跳转到错误页面
        } catch (NullPointerException ex) {
      %>
      <jsp:forward page="../error/err_url.jsp"/>
      <%}  %>
      </body>
    </html:html>
      

  3.   

    太乱了
    try和catch被<html>分开了
    把他们都放到<html>里不好吗
    用了好长时间我才找到try
      

  4.   

    不要把过多的逻辑方法表现层。
    -----------------------
    cownew开源团队,国内最活跃的开源团队之一,主要作品:sql翻译引擎、Hibernate建模工具,JDBC监控工具。
    网址:http://www.cownew.com
    blog:http://www.blogjava.net/huanzhugege
      

  5.   

    我是初学者,这些逻辑代码是为了防止没有权限的直接输入url进入,请问该如何简化呢?不要说太深奥的技术,我只会JAVA代码。