Eclipse JSP网页引用JAVA里的方法就报错
这个是我新写的两个JAVA类packagefff;publicclassTttext{publicstaticStringff(){return"ff";}}JSP页面<...
这个是我新写的两个
JAVA类
package fff;
public class Tttext {
public static String ff(){
return "ff";
}
}
JSP页面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="fff.Tttext" %>
<%
String ss=Tttext.ff();
%>
报错提示
2011-7-20 22:37:58 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [Unable to compile class for JSP:
An error occurred at line: 11 in the generated java file
Only a type can be imported. fff.Tttext resolves to a package
An error occurred at line: 5 in the jsp file: /text/WebContent/index.jsp
Tttext cannot be resolved
2: pageEncoding="utf-8"%>
3: <%@ page import="fff.Tttext" %>
4: <%
5: String ss=Tttext.ff();
6: %>
7: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
8: <html>
解决加分 展开
JAVA类
package fff;
public class Tttext {
public static String ff(){
return "ff";
}
}
JSP页面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="fff.Tttext" %>
<%
String ss=Tttext.ff();
%>
报错提示
2011-7-20 22:37:58 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [Unable to compile class for JSP:
An error occurred at line: 11 in the generated java file
Only a type can be imported. fff.Tttext resolves to a package
An error occurred at line: 5 in the jsp file: /text/WebContent/index.jsp
Tttext cannot be resolved
2: pageEncoding="utf-8"%>
3: <%@ page import="fff.Tttext" %>
4: <%
5: String ss=Tttext.ff();
6: %>
7: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
8: <html>
解决加分 展开
8个回答
2016-03-02 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
JSP网页引用JAVA里的方法就报错是因为缺少引入jar包。
1、引入单个包
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>//主要是这句
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
2、引入多个包
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>//主要是这句,中间用逗号隔开
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
1、引入单个包
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>//主要是这句
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
2、引入多个包
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>//主要是这句,中间用逗号隔开
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
展开全部
楼上两位说法都可能不对,我也喜欢在UBUBTU里面搞,是权限问题,激活ROOT帐户再用ROOT登录,就可以解决了,另外最好建议楼主用Meclipse for linux 因为Eclipse差件很难下载,因为国内很多地方都打不开Eclipse官网。可参考我空间Myeclipse for linux 下载地址和安装和安装
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我试过了 没有错
<%@ page language="java" import="ffff.Tttext" pageEncoding="gbk"%>
<%
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 'Hello.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">
</head>
<body>
<%
String s = Tttext.ff();
%>
您的访问是:<%=s %>
</body>
</html>
<%@ page language="java" import="ffff.Tttext" pageEncoding="gbk"%>
<%
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 'Hello.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">
</head>
<body>
<%
String s = Tttext.ff();
%>
您的访问是:<%=s %>
</body>
</html>
追问
注意 我用的是 eclipse 不是myeclipse 在myeclipse 里我也不报错 公司要求用eclipse
追答
哦,不好意思哈。。。。不过我没装Eclipse
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
发的很乱!An error occurred at line: 11 in the generated java file都搞不懂是哪里。
追问
我已经把所有代码都贴上了 他上面显示的就是这样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Tttext类型不能被解析
导包是不是导错了? 还是导了多次同一个包
导包是不是导错了? 还是导了多次同一个包
追问
没有呀 我就导了一次 我上面代码很清楚了呀
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询