急:jsp+javabean有错误,不知道错误在哪里?

紫罗兰Cherry 2004-01-07 09:24:40
源码如下:
Send.java
/*
*发送信息
*
*/

package com.hasons.bean;

import java.io.*;
import java.net.*;

public class Send
{
//属性
String host;
int port;

DataInputStream inStream;
DataOutputStream outStream;

public Send()
{
host="192.168.1.180";
port=8765;

try{

Socket client=new Socket(host,port);
inStream=new DataInputStream(client.getInputStream());
outStream=new DataOutputStream(client.getOutputStream());
client.setSoTimeout(3000);
}
catch(Exception e)
{}

}

public String SendMess()
{
String str="Hello";
try{

for(int index=1;index<10;index++)
{
outStream.writeUTF(str);
}
return("success");
}
catch(Exception e)
{
return("Fail");
}

}

}
该文件在D:\hasons\lib\com\hasons\bean\Send.class
Classpath中设定了:D:\hasons\lib。
在Dos下,输入java com.hasons.Send可以找到该类。

test2.jsp
<%@ page language="java" %>
<%@ page contentType="text/html;charset=gb2312" %>

<%@ page import="com.hasons.bean.*" %>
<jsp:useBean id="test1" class="com.hasons.bean.Send"/>

<html>
<head>
<title>测试</title>
</head>

<body>
<%=test1.SendMess()%>
Hello
<body>

在IE中执行test2.jsp时,出现下面的错误:
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: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\hasons\test2_jsp.java:7: package com.hasons.bean does not exist
[javac] import com.hasons.bean.*;
[javac] ^
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\hasons\test2_jsp.java:46: package com.hasons.bean does not exist
[javac] com.hasons.bean.Send test1 = null;
[javac] ^
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\hasons\test2_jsp.java:48: package com.hasons.bean does not exist
[javac] test1 = (com.hasons.bean.Send) pageContext.getAttribute("test1", PageContext.PAGE_SCOPE);
[javac] ^
[javac] C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\hasons\test2_jsp.java:51: package com.hasons.bean does not exist
[javac] test1 = (com.hasons.bean.Send) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "com.hasons.bean.Send");
[javac] ^
[javac] 4 errors
...

想不明白是为什么。论坛中搜索也没找到解决办法,大家多帮忙啊!
先谢!

...全文
36 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
紫罗兰Cherry 2004-01-08
  • 打赏
  • 举报
回复
多谢,解决了,给分!

文件是要放在:虚拟目录对应的目录下的web-inf\classes下。
allof01 2004-01-07
  • 打赏
  • 举报
回复
刚刚扫了一下FAQ,倒是有很多篇贴子提到这个问题啊。给你转两篇,还有很多。建议找个时间研究下TOMCAT的目录结构以及怎么样在TOMCAT下建立WEB APPLICATION。差点忘了,还不知道你的是不是TOMCAT。无所谓了,反正一通百通。
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=155357
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=125324
allof01 2004-01-07
  • 打赏
  • 举报
回复
我这边已经测试通过了,没看有没有其他错误,test2.jsp是可以运行的。
allof01 2004-01-07
  • 打赏
  • 举报
回复
是放到你的webapp/WEB-INF/classes下,假如你是这样访问http://localhost:8080/test2.jsp,那么webapp是应该你的test2.jsp所在的目录,。
IT源哥 2004-01-07
  • 打赏
  • 举报
回复
你把文件夹放到web-inf/class里面试一下
紫罗兰Cherry 2004-01-07
  • 打赏
  • 举报
回复
是放在:
D:\hasons\web-inf\classes下吗。

是否还需要其他的设置!
wujinpinga 2004-01-07
  • 打赏
  • 举报
回复
另外也可以这样写test2.jsp试试看
<%@ page language="java" %>
<%@ page contentType="text/html;charset=gb2312" %>

<%@ page import="com.hasons.bean.*" %>

<html>
<head>
<title>测试</title>
</head>

<body>
<% Send test1 = new Send();%>
<%=test1.SendMess()%>
Hello
<body>
wujinpinga 2004-01-07
  • 打赏
  • 举报
回复
Send.class得放在\web-inf\classes\com\hasons\bean\下
allof01 2004-01-07
  • 打赏
  • 举报
回复
暂时没条件测试,你把com.hasons.bean.Send.class复制到WEB-INF目录下的classes下试试,当然得依照包路径建立相同的目录结构
WEB-INF/classes/com/hasons/bean/Send.class
希望有帮助。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧