本文目錄一覽:
- 1、jsp中catch(ClassNotFoundException e){ out.print(e); }是什麼意思
- 2、jsp怎麼使用.class文件?tomcat
- 3、關於jsp中第一次請求頁面try catch問題
- 4、jsp的try、catch 是什麼意思
- 5、JSP try catch 高手幫幫忙啊
- 6、JSP代碼 我不知道怎麼放入try{}和catch{}
jsp中catch(ClassNotFoundException e){ out.print(e); }是什麼意思
拋異常,然後在控制台輸出異常內容。
ClassNotFoundException是個異常處理類,要是你程序中類加載錯誤的話,就會拋出異常。
常見原因:
1 所需要的支持類庫放錯了地方,並沒有放在類路徑裡面
2 使用了重複的類庫,且版本不一致。導致低版本的被優先使用。
3 類名錯了,一般是使用Class.forName的時候,手工指定了類名的情況。
4 沒有導入純JAVA驅動包。
jsp怎麼使用.class文件?tomcat
jsp經過編譯後會生成.class文件,二進制字節碼文件,只有發布到tomcat才可以運行。
jsp直接放到Webapps目錄下就可以了,步驟如下:
Tomcat的Webapps目錄是Tomcat默認的應用目錄,務器啟動時,會加載所有這個目錄 下的應用。
也可以將JSP程序打包成一個war包放在目錄下,服務器會自動解開這個war包,並在這個目錄下生成一個同名的文件夾。
一個war包就是有特 性格式的jar包,它是將一個Web程序的所有內容進行壓縮得到。
在程序執行中打包:
try{
string strjavahome = system.getproperty(“java.home”);
strjavahome = strjavahome.substring(0,strjavahome.lastindexof(\\))+”\\bin\\”;
runtime.getruntime().exec(“cmd /c start “+strjavahome+”jar cvf hello.war c:\\tomcat5.0\\webapps\\root\\*”);
}
catch(exception e){system.out.println(e);}
webapps這個默認的應用目錄也是可以改變。
打開Tomcat的conf目錄下的server.xml文件,找到下面內容即可:
Host name=”localhost” debug=”0″ appBase=”webapps” unpackWARs=”true” autoDeloy=”true” xmlValidation=”falase” xmlNamespaceAware=”false”
關於jsp中第一次請求頁面try catch問題
java中,方法級變量必須初始化。
就是因為r沒有初始化,才報錯的。改成。
int r=0;
jsp的try、catch 是什麼意思
是錯誤捕捉:
try
{
code; //將自己的代碼放在其中;
}
catch(e) //如果上面的代碼有錯誤,這裡就捕獲
{
alert(e.number); //獲得錯誤信息
}
JSP try catch 高手幫幫忙啊
數據庫操作會出現SQLException,所以你要寫異常處理語句,無論你當前有沒有出現錯誤都應該寫,這是程序員應有的規範。至於try catch捕獲異常你會用的話,建議你去看一本JAVA基礎教程,把J2SE學習學習,JSP往深里發展還是JAVA
JSP代碼 我不知道怎麼放入try{}和catch{}
try{
//代碼區
}catch(Exception e){
//異常處理
}
代碼區如果有錯誤,就會返回所寫異常的處理。
首先要清楚,如果沒有try的話,出現異常會導致程序崩潰。
而try則可以保證程序的正常運行下去,例如:
try{
int i = 1/0;
}catch(Exception e){
}
一個計算的話,如果除數為0,則會報錯,如果沒有try的話,程序直接崩潰。用try的話,則可以讓程序運行下去,並且輸出為什麼出錯!
try catch 是捕捉try部分的異常,當沒有trycatch的時候,如果出現異常則程序報錯,加上trycatch,出現異常程序正常運行,只是把錯誤信息存儲到Exception里,所以catch是用來提取異常信息的,可以在Catch部分加上一句System.out.println(e.ToString());,如果出現異常可以把異常打印出來
try-catch-finally示例:
public class TestException
{
public TestException()
{
}
boolean testEx() throws Exception
{
boolean ret = true;
try
{
ret = testEx1();
}
catch (Exception e)
{
System.out.println(“testEx, catch exception”);
ret = false;
throw e;
}
finally
{
System.out.println(“testEx, finally; return value=” + ret);
return ret;
}
}
boolean testEx1() throws Exception
{
boolean ret = true;
try
{
ret = testEx2();
if (!ret)
{
return false;
}
System.out.println(“testEx1, at the end of try”);
return ret;
}
catch (Exception e)
{
System.out.println(“testEx1, catch exception”);
ret = false;
throw e;
}
finally
{
System.out.println(“testEx1, finally; return value=” + ret);
return ret;
}
}
boolean testEx2() throws Exception
{
boolean ret = true;
try
{
int b = 12;
int c;
for (int i = 2; i = -2; i–)
{
c = b / i;
System.out.println(“i=” + i);
}
return true;
}
catch (Exception e)
{
System.out.println(“testEx2, catch exception”);
ret = false;
throw e;
}
finally
{
System.out.println(“testEx2, finally; return value=” + ret);
return ret;
}
}
public static void main(String[] args)
{
TestException testException1 = new TestException();
try
{
testException1.testEx();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
輸出結果:
i=2
i=1
testEx2, catch exception
testEx2, finally; return value=false
testEx1, finally; return value=false
testEx, finally; return value=false
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/158918.html