当前位置: 代码迷 >> Java Web开发 >> jsp <%%>程序段里的catch语句里怎么弹出提示框?
  详细解决方案

jsp <%%>程序段里的catch语句里怎么弹出提示框?

热度:286   发布时间:2013-01-08 01:16:18.0
jsp <%%>程序段里的catch语句里怎么弹出提示框?
<%
request.setCharacterEncoding("utf-8");//防止乱码

String id  = request.getParameter("id");
int a=0;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:student");
Statement stat = conn.createStatement();

String sql = "delete from chengji where id = '" +id+ "'";

int i = stat.executeUpdate(sql);
a=a/i;
out.print("成功删除" + i + "行记录!");
stat.close();
conn.close();

}
catch(Exception e){ out.print("<%=check()%>"); }
%>


代码里的 catch语句体里该怎么写?
我在开头定义的下面的
<script language="javascript" type="text/javascript">
function check(){ alert("删除记录失败!请检查学号是否存在!");}
</script>

求老师们指教下
快期末考试了、、蛋疼啊、、
搜索更多相关主题的帖子: where  sql  

----------------解决方案--------------------------------------------------------
矮油、、不好意思、、开头的try{ 给掉了、、、
----------------解决方案--------------------------------------------------------
我擦、、眼神不好、、咳咳 老师同学们请无视2楼吧
----------------解决方案--------------------------------------------------------
<%%>里是不能调用到JS的 直接打印一个JS就行了
程序代码:
out.print("<script language="javascript" type="text/javascript">check()</script>");


----------------解决方案--------------------------------------------------------
谢谢前辈啦 有什么方法可以弹出提示框确定之后直接返回前一个页面嘛?
----------------解决方案--------------------------------------------------------
<script language="javascript" type="text/javascript">
function check(){ alert("删除记录失败!请检查学号是否存在!");location.href="上一个页面的链接";}
</script>
----------------解决方案--------------------------------------------------------
嘿嘿 我又来了 说我的java 文件有错?我测试过java文件木有错啊
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 153 in the generated java file
Syntax error, insert "else Statement" to complete IfStatement

An error occurred at line: 153 in the generated java file
Syntax error, insert "}" to complete Block

An error occurred at line: 164 in the generated java file
Syntax error on token "}", delete this token

An error occurred at line: 165 in the generated java file
Syntax error, insert "}" to complete ClassBody

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
----------------解决方案--------------------------------------------------------
这是java代码:

package mybean;

import java.io.*;
import java.sql.*;
public class A{
    String id="";
    String name="";
    String fenshu="";

  public A()
   {   
     id="";
     name="";
     fenshu="";
   }
  public void setId(String id)
   {
     this.id=id;
   }
  public String getId()
   {
     return id;
   }
  public void setName(String name)
   {
     this.name=name;
   }
  public String getName()
   {
     return name;
   }
  public void setFenshu(String fenshu)
   {
     this.fenshu=fenshu;
   }
  public String getFenshu()
   {
     return fenshu;
   }

  public void conn()
   {
     if(id!="")
      {
        try{
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection conn1 = DriverManager.getConnection("jdbc:odbc:student");
              Statement stat1 = conn1.createStatement();
              String sql1 = "select * from chengji where id='"+id+"'";
              ResultSet rs1 = stat1.executeQuery(sql1);

              while(rs1.next())
                   {

                     id=rs1.getString(1);
                     name=rs1.getString(2);
                     fenshu=rs1.getString(3);
                   }
             if(rs1.next()==false)
                 {
                   id="";name="";fenshu="";
                 }
             else
                 {
                 }
             stat1.close();
             conn1.close();
           }
         
         catch(Exception e)
           {
             System.out.print("请规范操作!");
           }
      }
      
   else
      {
      }
   }
  public static void main(String[] args)
   {

     A a=new A();

     a.setId("002");
     a.conn();
     if(a.name!="")
      {
         System.out.println("    id:"+a.id);
         System.out.println("  name:"+a.name);
         System.out.println("fenshu:"+a.fenshu);
      }
     else
       {
          System.out.println("数据库里没有这个id!");
       }
   }

}
----------------解决方案--------------------------------------------------------
前辈们真的很抱歉浪费你们时间了 是我自己的错 我把表单的action 地址写错了、、转到别的页面才错了 灰常抱歉额、、、唉、、浪费了一天时间 数据库都没怎么复习、、明天要就考数据库了
----------------解决方案--------------------------------------------------------

像你这阶段的数据库更本就不难

----------------解决方案--------------------------------------------------------