第一次使用开发工具 只是知道要在src下建包
结果在jsp里该怎么导入class的时候就不会了
诚心请教 最好谁能详细地写出来
谢谢
结果在jsp里该怎么导入class的时候就不会了
诚心请教 最好谁能详细地写出来
谢谢
解决方案 »
- 求sql or hql
- 请问List集合存了几个字符串,我要获取第几个字符串的时候,结果越界了,如何解决?
- 如何用java发邮件
- seve(entity)的时候,entity里的外键如何操作?
- 如何用java采用GET方式向服务器发送参数
- 那位好心的人帮帮忙啊 全部家当 数据库问题
- 谁能帮我看下这个servelet 为什么输出流输不出去 郁闷死了
- input type怎么获取客户端的绝对路径
- 怎样才能将JMS和struts联系起来呢?有实例吗?
- 我是一个j2ee的初学者,在按照j2eetutorial1.4里的实例做时,总是出现XML错误,请帮忙!
- jsp接收servlet传递的字符串数组的问题
- hibernate问题:[调用方法时发生 com.sun.jdi.InvocationException]
你写上类名然后按alt+/
编译,class文件在classes包里
在JSP上直接用命令,如<%@ page import="com.huawei.dbuse.DBFileInfo" %>
这样导入就行了撒
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 reportmessage 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
崩溃了...哪里不对啊?一用标签就不对...
<jsp:useBean id="c" class="com.javatest.bean.Counter"></jsp:useBean>
但是
<jsp:setProperty name="c" property="count"/>
为什么count的值不显示呢?
这个方法只是对进行赋值count
就像这样<jsp:setProperty name="c" property="count" param=***/>
如果要取出count的值可以用
<jsp:getProperty name="c" property="count" />
JSP中导入某个文件夹。。
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>