<%@ page contentType="text/html;charset=GB2312" %><HTML>
<BODY>
<%
a a1=new a();
%>
<P>您是第
<%=a1.i%>
个访问本站的客户。
</BODY>
</HTML>本目录下包ad内的java文件是public class a{
int i=7;
public static void main(String[] args){
a a1=new a();
System.out.println(a1.i); }}
jsp运行后出现下面的问题
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 7 in the jsp file: /1.jsp
a cannot be resolved to a type
4: <BODY>
5:
6: <%
7: a a1=new a();
8: %>
9:
10: <P>您是第
An error occurred at line: 7 in the jsp file: /1.jsp
a cannot be resolved to a type
4: <BODY>
5:
6: <%
7: a a1=new a();
8: %>
9:
10: <P>您是第
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
<BODY>
<%
a a1=new a();
%>
<P>您是第
<%=a1.i%>
个访问本站的客户。
</BODY>
</HTML>本目录下包ad内的java文件是public class a{
int i=7;
public static void main(String[] args){
a a1=new a();
System.out.println(a1.i); }}
jsp运行后出现下面的问题
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 7 in the jsp file: /1.jsp
a cannot be resolved to a type
4: <BODY>
5:
6: <%
7: a a1=new a();
8: %>
9:
10: <P>您是第
An error occurred at line: 7 in the jsp file: /1.jsp
a cannot be resolved to a type
4: <BODY>
5:
6: <%
7: a a1=new a();
8: %>
9:
10: <P>您是第
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
加上<%@page import="类">
在顶部加上 <%@ page import="类名">
我导入类之后还是出现同样的问题
<%@ page contentType="text/html;charset=GB2312" import="java.util.*,ad.*"%><HTML>
<BODY>
<%
a a1=new a();
%>
<P>您是第
<%=a1.i%>
个访问本站的客户。
</BODY>
</HTML>
不过也不对呀。。 你要是没import的话,在myEclipseJSP页面会有错误提示的
楼上的说我都试过了都不行,谁能写一个调用java文件的JSP发给我让我运行试试
.cn
谢谢各位了
小弟才刚刚自学JSP,小弟在此拜谢了
//这里的 “你的类”是完全限定名,就是带上包的类名。比如:你的类为 ad.a //有点不习惯用小写字母来命名ad是你的包名,这样用import导入没有问题的
C:\JAVA\MYCLASS首先把C:\JAVA放在classpath环境变量中这样在页面中调用可以用 MYCLASS.类名 使用(记得先重启服务器)
将ad所在的目录放在环境变量
使用a类时这样用
ad.a newclass = new ad.a();