jsp怎么放catch,怎么使用jsp

发布时间:2023-12-08

jsp怎么放catch,怎么使用jsp

更新:

本文目录一览:

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