jsp中调用java类的方法,用new创建一个对象运行到new对象这里就报错,怎么整? 15
publicclasstest{publicvoidtest(){}publicIntegerget(){return12;}}jsp文件<%@pagelanguage=...
public class test {
public void test(){
}
public Integer get(){
return 12;
}
}
jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@pageimport="a.test"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
agrThis is my JSP page. <br>
<%test t=new test();
out.print(t.get());
%>
</body>
</html>
报错:org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 7 in the generated java file
Only a type can be imported. a.test resolves to a package
An error occurred at line: 28 in the jsp file: /WebRoot/index.jsp
test cannot be resolved to a type
25: <body>
26:
27: agrThis is my JSP page. <br>
28: <%test t=new test(); %>
29:
30: <% int a=9;
31: out.print(a); 展开
public void test(){
}
public Integer get(){
return 12;
}
}
jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@pageimport="a.test"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
agrThis is my JSP page. <br>
<%test t=new test();
out.print(t.get());
%>
</body>
</html>
报错:org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 7 in the generated java file
Only a type can be imported. a.test resolves to a package
An error occurred at line: 28 in the jsp file: /WebRoot/index.jsp
test cannot be resolved to a type
25: <body>
26:
27: agrThis is my JSP page. <br>
28: <%test t=new test(); %>
29:
30: <% int a=9;
31: out.print(a); 展开
4个回答
展开全部
没在头部导入包,JSP根本不知道这个Java类是从什么地方跑出来的,所以语法错误,另外还报错说你类型格式不对,这个可以也看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public void test(){
}
构造函数不能有返回值
public test(){
}
}
构造函数不能有返回值
public test(){
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
导包导的不对,说的很清楚,a.test不是一个包,你的写法有问题,导致test类识别不了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询