当前位置: 技术问答>java相关
为什么在jsp中写一个String g()后会出错?
来源: 互联网 发布时间:2015-02-07
本文导语: ==文件内容== ==出错内容== org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated. C:javatomcatworklocalhost_8080%2Fjspbbs_0002ftest_0002ejsptest_jsp_18.java:53: '}' expected. out =...
==文件内容==
==出错内容==
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
C:javatomcatworklocalhost_8080%2Fjspbbs_0002ftest_0002ejsptest_jsp_18.java:53: '}' expected.
out = pageContext.getOut();
^
C:javatomcatworklocalhost_8080%2Fjspbbs_0002ftest_0002ejsptest_jsp_18.java:57: Statement expected.
public String g(){
^
C:javatomcatworklocalhost_8080%2Fjspbbs_0002ftest_0002ejsptest_jsp_18.java:62: Type expected.
out.write("rn");
^
3 errors, 1 warning
==出错内容==
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
C:javatomcatworklocalhost_8080%2Fjspbbs_0002ftest_0002ejsptest_jsp_18.java:53: '}' expected.
out = pageContext.getOut();
^
C:javatomcatworklocalhost_8080%2Fjspbbs_0002ftest_0002ejsptest_jsp_18.java:57: Statement expected.
public String g(){
^
C:javatomcatworklocalhost_8080%2Fjspbbs_0002ftest_0002ejsptest_jsp_18.java:62: Type expected.
out.write("rn");
^
3 errors, 1 warning
|
把你的方法封装到一个类里,然后创建这个类的一个实例,再用:
浏览器中输出:
this is a test
浏览器中输出:
this is a test
|
你要用!声明,因为JSP编译成SERVLET时,JSP中的内容是包含在类的一个函数中的,函数中当然不能包含函数。
使用!可以将该函数声明为生成的SERVLET类的一个函数