结果在jsp里该怎么导入class的时候就不会了
诚心请教 最好谁能详细地写出来
谢谢
8 个解决方案
#1
在myclipse可以自动的.
你写上类名然后按alt+/
你写上类名然后按alt+/
#2
首先要保证你建的是一个WEB工程,其次,JSP页面要在webroot目录下,你代码在src目录下保存后会自动
编译,class文件在classes包里
在JSP上直接用命令,如<%@ page import="com.huawei.dbuse.DBFileInfo" %>
这样导入就行了撒
编译,class文件在classes包里
在JSP上直接用命令,如<%@ page import="com.huawei.dbuse.DBFileInfo" %>
这样导入就行了撒
#3
javaBean:
package com.javatest.bean;
public class Counter {
public Counter()
{
}
private int count=0;
public int getCount() {
count++;
return count;
}
public void setCount(int count) {
this.count = count;
}
}
jsp:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="com.javatest.bean.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP '5.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>
This is my JSP page.
<jsp:useBean id="c" class="Counter"></jsp:useBean>
<jsp:setProperty name="c" property="getCount"/>
<br>
</body>
</html>
报错:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /5.jsp(28,4) The value for the useBean class attribute Counter is invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: /5.jsp(28,4) The value for the useBean class attribute Counter is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.20
崩溃了...哪里不对啊?一用标签就不对...
package com.javatest.bean;
public class Counter {
public Counter()
{
}
private int count=0;
public int getCount() {
count++;
return count;
}
public void setCount(int count) {
this.count = count;
}
}
jsp:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="com.javatest.bean.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP '5.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>
This is my JSP page.
<jsp:useBean id="c" class="Counter"></jsp:useBean>
<jsp:setProperty name="c" property="getCount"/>
<br>
</body>
</html>
报错:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /5.jsp(28,4) The value for the useBean class attribute Counter is invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: /5.jsp(28,4) The value for the useBean class attribute Counter is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.20
崩溃了...哪里不对啊?一用标签就不对...
#4
好像是导入包这么写就可以
<jsp:useBean id="c" class="com.javatest.bean.Counter"></jsp:useBean>
但是
<jsp:setProperty name="c" property="count"/>
为什么count的值不显示呢?
<jsp:useBean id="c" class="com.javatest.bean.Counter"></jsp:useBean>
但是
<jsp:setProperty name="c" property="count"/>
为什么count的值不显示呢?
#5
<jsp:setProperty name="c" property="count"/>
这个方法只是对进行赋值count
就像这样<jsp:setProperty name="c" property="count" param=***/>
如果要取出count的值可以用
<jsp:getProperty name="c" property="count" />
这个方法只是对进行赋值count
就像这样<jsp:setProperty name="c" property="count" param=***/>
如果要取出count的值可以用
<jsp:getProperty name="c" property="count" />
#6
<%@page import="com.javatest.bean.*" %>
JSP中导入某个文件夹。。
JSP中导入某个文件夹。。
#7
你的java文件没问题
jsp改成这样就可以了:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="a.Counter" %>
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<jsp:useBean id="c" class="a.Counter"></jsp:useBean>
<jsp:getProperty property="count" name="c"/>
</body>
</html>
jsp改成这样就可以了:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="a.Counter" %>
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<jsp:useBean id="c" class="a.Counter"></jsp:useBean>
<jsp:getProperty property="count" name="c"/>
</body>
</html>
#8
忘了说了,我的a是我的java文件的包名,你把它改成你的包名com.javatest.bean就行了
#1
在myclipse可以自动的.
你写上类名然后按alt+/
你写上类名然后按alt+/
#2
首先要保证你建的是一个WEB工程,其次,JSP页面要在webroot目录下,你代码在src目录下保存后会自动
编译,class文件在classes包里
在JSP上直接用命令,如<%@ page import="com.huawei.dbuse.DBFileInfo" %>
这样导入就行了撒
编译,class文件在classes包里
在JSP上直接用命令,如<%@ page import="com.huawei.dbuse.DBFileInfo" %>
这样导入就行了撒
#3
javaBean:
package com.javatest.bean;
public class Counter {
public Counter()
{
}
private int count=0;
public int getCount() {
count++;
return count;
}
public void setCount(int count) {
this.count = count;
}
}
jsp:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="com.javatest.bean.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP '5.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>
This is my JSP page.
<jsp:useBean id="c" class="Counter"></jsp:useBean>
<jsp:setProperty name="c" property="getCount"/>
<br>
</body>
</html>
报错:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /5.jsp(28,4) The value for the useBean class attribute Counter is invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: /5.jsp(28,4) The value for the useBean class attribute Counter is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.20
崩溃了...哪里不对啊?一用标签就不对...
package com.javatest.bean;
public class Counter {
public Counter()
{
}
private int count=0;
public int getCount() {
count++;
return count;
}
public void setCount(int count) {
this.count = count;
}
}
jsp:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="com.javatest.bean.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP '5.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>
This is my JSP page.
<jsp:useBean id="c" class="Counter"></jsp:useBean>
<jsp:setProperty name="c" property="getCount"/>
<br>
</body>
</html>
报错:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /5.jsp(28,4) The value for the useBean class attribute Counter is invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: /5.jsp(28,4) The value for the useBean class attribute Counter is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3320)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.20
崩溃了...哪里不对啊?一用标签就不对...
#4
好像是导入包这么写就可以
<jsp:useBean id="c" class="com.javatest.bean.Counter"></jsp:useBean>
但是
<jsp:setProperty name="c" property="count"/>
为什么count的值不显示呢?
<jsp:useBean id="c" class="com.javatest.bean.Counter"></jsp:useBean>
但是
<jsp:setProperty name="c" property="count"/>
为什么count的值不显示呢?
#5
<jsp:setProperty name="c" property="count"/>
这个方法只是对进行赋值count
就像这样<jsp:setProperty name="c" property="count" param=***/>
如果要取出count的值可以用
<jsp:getProperty name="c" property="count" />
这个方法只是对进行赋值count
就像这样<jsp:setProperty name="c" property="count" param=***/>
如果要取出count的值可以用
<jsp:getProperty name="c" property="count" />
#6
<%@page import="com.javatest.bean.*" %>
JSP中导入某个文件夹。。
JSP中导入某个文件夹。。
#7
你的java文件没问题
jsp改成这样就可以了:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="a.Counter" %>
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<jsp:useBean id="c" class="a.Counter"></jsp:useBean>
<jsp:getProperty property="count" name="c"/>
</body>
</html>
jsp改成这样就可以了:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="a.Counter" %>
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<jsp:useBean id="c" class="a.Counter"></jsp:useBean>
<jsp:getProperty property="count" name="c"/>
</body>
</html>
#8
忘了说了,我的a是我的java文件的包名,你把它改成你的包名com.javatest.bean就行了