我想你是没有加包名才会这样的!在你的Bean程序开头写有包名的,
比如:
package forms;
import java.util.*;
import java.sql.*;forms就是包名,你只要把那个JavaBean编译后的class放在/WEB-INF/classes/forms下就可以啦!
比如:
package forms;
import java.util.*;
import java.sql.*;forms就是包名,你只要把那个JavaBean编译后的class放在/WEB-INF/classes/forms下就可以啦!
解决方案 »
- sesson.getAttribute()返回值转换类型
- ☆☆☆☆☆☆☆☆☆☆☆☆☆莱鸟禁飞区!!!高手请进☆☆☆☆☆☆☆☆☆☆☆☆☆
- 如何将数据库,服务器,程序一起打包?
- (关于checkbox)严重:值“fales”并非该属性的一个列举值。
- 为什么有的电脑里<input name="imports" type="file" id="imports" readonly="true">正常使用,而有的电脑点击"浏览"没反应?
- iBatis动态SQL标签常用写法总结
- 谁有Struts和validation方面的书?先放50分.
- 求教:jsp报错
- 有哪位高手知道怎么在resin里可以将数据库里读出来的数据可以保存为excel格式文件?
- 关于tomcat7、tomcat8的一个jsp乱码问题,难道是bug?求释疑
- jsp调用javabean时候,怎么总是找不到类?
- (在线等待)小弟想学jsp,请问各位哪些书比较适合!
┏━★━━◆━━★━┓
♂欢|◢CSDN◣|使♂ ▲自由保存帖子,浏览,关注检测
┃迎|◥论坛助手◤|用┃ ▲完善的CSDN客户端工具
┗━☆━━◇━━━☆┛ ▲自动添加签名......让你更快,更爽,更方便地上CSDN...
http://www.csdn.net/expert/topic/573/573604.xml
http://www.chinaok.net/csdn/csdn.zip
然后再建一个文件夹 /WEB-INF/classes/XXX 注意大小写!
<jsp:useBean id="xxx" scope="page" class="XXX.Txxx"/>
而那个Txxx就是你的类!所在文件名师Txxx.
//JSP文件1:index.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>JSP Script E-Mail</title>
</head>
<body>
<p align="center">Send your E-Mail here</p>
<form action="BeanMailer.jsp" method="post">
<table>
<tr>
<td>From</td><td><input type="text" size="40" name="from"></td>
</tr>
<tr>
<td>To</td><td><input type="text" size="40" name="to"></td>
</tr>
<tr>
<td>Subject</td><td><input type="text" size="40" name="subject"></td>
</tr>
<tr>
<td></td><td><textarea cols="60" rows="20" name="message"></textarea></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="sumbit" value="SEND"></td>
</tr>
</table>
</form>
</body>
</html>
//JSP文件2:BeanMailer.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>E-Mail Form</title>
</head>
<body>
<p align="center">Send Mail</p>
<jsp:useBean id="email" class="mailer.SMTPBean"/>
<%
String from,to,subject,message;
try{
from=request.getParameterValues("from")[0];
to=request.getParameterValues("to")[0];
subject=request.getParameterValues("subject")[0];
message=request.getParameterValues("subject")[0];
}
catch(Exception e){
out.println("You have to use the Form to send email from here .");
out.println("Click <a href=\"index.jsp\">here</a> for the form.<br>");
out.flush();
return;
}
%>
<jsp:setProperty name="email" property="smtpServer" value="smtp.163.com"/>
<%
try{
email.sendMail(from,to,subject,message);
out.println("Sending your mail...");
}
catch(Exception e){
out.println(e.getMessage()+"<br>");
}
%>
<p>and one more times with more details.</p>
<%
try{
email.connect();
out.println("Connecting....");
out.println(email.getServerReply());
out.println("<br>");
}
catch(SMTPException e){
out.println(e.getMessage()+"<br>");
}
try{
out.println("Hailing....");
email.hail(from,to);
out.println(email.getServerReply());
out.println("<br>");
}
catch(SMTPException e){
out.println(e.getMessage()+"<br>");
}
try{
out.println("Sending message....");
email.sendMessage(from,to,subject,message);
out.println(email.getServerReply());
out.println("<br>");
}
catch(SMTPException e){
out.println(e.getMessage()+"<br>");
}
try{
out.println("Logging off....");
email.logout();
out.println(email.getServerReply());
out.println("<br>");
}
catch(SMTPException e){
out.println(e.getMessage()+"<br>");
}
%>
</body>
</html>
//JAVA Bean文件:
package mailer;//For a comprehensive tutorial as well as the current SMTP protocal
//go to http://www.jspinsider.com/tutorials/.import java.io.*;
import java.net.*;
import java.text.*;
import java.util.*;
import mailer.SMTPException;public class SMTPBean implements Serializable{
private Socket smtp;
private BufferedReader input;
private PrintStream output;
private String smtpServer = "smtp.163.com";
private String serverReply;
private int port = 25;
public SMTPBean(){
}
public void sendMail(String mailfrom,String mailto,String subject,String message)
throws SMTPException{
connect();
hail(mailfrom,mailto);
sendMessage(mailfrom,mailto,subject,message);
logout();
}
public void connect() throws SMTPException{
try{
smtp = new Socket(smtpServer,port);
input = new BufferedReader(new InputStreamReader(smtp.getInputStream()));
output = new PrintStream(smtp.getOutputStream());
serverReply = input.readLine();
if(serverReply.charAt(0)=='2' || serverReply.charAt(0)=='3'){
}
else{
throw new SMTPException("Error connecting to SMTP server "
+ smtpServer + "on port " + port);
}
}catch(Exception e){
throw new SMTPException(e.getMessage());
}
}
public void hail(String mailfrom,String mailto) throws SMTPException{
if(submitCommand("HELLO" + smtpServer))
throw new SMTPException("Error ocurred during HELLO command.");
if(submitCommand("MAIL FROM:" + mailfrom))
throw new SMTPException("Error during MAIL command");
if(submitCommand("RCPT TO:" + mailto))
throw new SMTPException("Error during RCPT command");
}
public void sendMessage(String mailfrom,String mailto,String subject,String message)
throws SMTPException{
Date ldate_today = new Date(System.currentTimeMillis());
SimpleDateFormat lgmt_date = new SimpleDateFormat("d MMM YYYY HH:MM:SS 'GMT'");
lgmt_date.setTimeZone(TimeZone.getTimeZone("GMT"));
lgmt_date.format(ldate_today);
if(submitCommand("DATA")){
throw new SMTPException("Error during DATA command");
}
String header = "From:" + mailfrom + "\r\n";
header += "To:" + mailto + "\r\n";
header += "Subject:" + subject + "\r\n";
header += "Date:" + lgmt_date +"\r\n\r\n";
if(submitCommand(header + message + "\r\n"))
throw new SMTPException("Eror during mail transmission.");
}
private boolean submitCommand(String command) throws SMTPException{
try{
output.print(command + "\r\n");
serverReply = input.readLine();
if(serverReply.charAt(0)=='4' || serverReply.charAt(0)=='5')
return true;
else
return false;
}
catch(Exception e){
throw new SMTPException(e.getMessage());
}
}
public String getServerReply(){
return serverReply;
}
public int getPort(){
return port;
}
public void setPort(int newPort){
port = newPort;
}
public String getSmtpServer(){
return smtpServer;
}
public void setSmtpServer(String newSmtpServer){
smtpServer = newSmtpServer;
}
public void logout() throws SMTPException{
try{
if(submitCommand("QUIT"))
throw new SMTPException("Error during QUIT command");
input.close();
output.flush();
output.close();
smtp.close();
}catch(Exception e){
}
}
}//Java Bean中引用的类的文件
package mailer;
//For a comprehensive tutorial as well as the current SMTP protocal
//go to http://www.jspinsider.com/tutorial/insider.html.public class SMTPException extends Exception{
private String message;
public SMTPException(String message){
this.message = message;
}
public String getMessage(){
return message;
}
}
当然在你的BEAN里也要 Package
当然在你的BEAN里也要 Package