2013-03-22 70 views
0

在瀏覽器中顯示一個特定的錯誤,我做了一個javabean類和error.jsp。問題是這個我想在error.jsp中顯示特定的異常。所以我做了錯誤的變量,我想誤差進來錯誤變量這樣我就可以向用戶顯示....我想通過jsp

package mypack; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 

public class StudentBean { 
    int roll, marks; 
    String name, grade; 
    String error; 
    public String getError() { 
     return error; 
    } 
    public void setError(String error) { 
     this.error = error; 
    } 
    public int getMarks() { 
     return marks; 
    } 
    public String getName() { 
     return name; 
    } 
    public String getGrade() { 
     return grade; 
    } 
    public int getRoll() { 
     return roll; 
    } 
    public void setRoll(int roll) { 
     this.roll = roll; 
    } 
    public boolean lookup() { 
     try { 
      Class.forName("oracle.jdbc.driver.OracleDriver"); 
      Connection con = DriverManager.getConnection(
        "jdbc:oracle:thin:@localhost:1521:xe", "system", "oracle"); 
      PreparedStatement pst = con 
        .prepareStatement("select * from student where roll=?"); 
      pst.setInt(1, roll); 
      ResultSet rs = pst.executeQuery(); 
      if (rs.next()) { 
       name = rs.getString(1); 
       roll = rs.getInt(2); 
       marks = rs.getInt(3); 
       grade = rs.getString(4); 
      } 
     } catch (Exception e) { 
      System.out.println("Generated Exception " + e); 
      error = e.getMessage(); 
     } 
     return true; 
    } 
} 
+0

你可以顯示你的jsp代碼嗎? – Bhushan 2013-03-22 04:11:25

回答

0

試圖處理所有的異常,這是可能來在你的代碼一樣

+0

對不起朋友,我想這個任何錯誤來了,然後它將存儲在錯誤變量,我想打印在error.jsp .. – Arpit 2013-03-22 05:43:00

+0

@ user2168358你可以打印錯誤在jsp使用{錯誤} – PSR 2013-03-22 05:46:54

+0

對不起朋友我會採取異常類... plz ..看看.. – Arpit 2013-03-23 05:47:13