例如:
String[] args = new String[3]{"a","b","c"};
类名.main(args);
String[] args = new String[3]{"a","b","c"};
类名.main(args);
解决方案 »
- jsp显示本地图片
- 如何去除List中重复的元素,在线等,急。有答案立马结贴
- struts里错误信息的返回
- 请问maven2怎样配置使它指向的web目录不是src/main/webapp 而是WebRoot,src/main/java变成src/main
- forEach嵌套的小问题
- jbpm3.1.4和spring2.0整合报错
- 大家帮帮我啊!!!
- 请问如果设置Log4J才可以使其日志既单独输出又能输出到主日志文件
- jboss数据库连接池问题
- 如果JSP文件在根网站的根目录,被调用的JAVABEAN在子目录BEAN,该如何调用(我每粉了)
- JS中如何显示“是”或“否”对话框???
- 写过:系统建设技术方案 XDJM请给点意见!
如果是静态类的话,可以直接调用她的方法。
e.g.<%
Yourclass test=new Yourclass();
Yourclass.yourmethod();
%>
yourClassName.main(new String[] args)
不过这样不好.
看你的代码.可以直接定义类后调用listMails("abc","abc","abc");
方法
new Class();
%>
你的class名 test=new 你的class名();
test.你的class里面的方法名();
%>
package my;import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;import javax.mail.BodyPart;
import javax.mail.FetchProfile;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.UIDFolder;
import javax.mail.URLName;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeUtility;
import com.sun.mail.pop3.POP3Folder;
/**
* 邮件接收演示例子
* @author liudong
*/
public class MailFetcher {
public static void listMails(String host,String user,String password)
throws IOException, MessagingException {
listMails(host,110,user,password);
}
public static void listMails(String host,int port,String user,String password)
throws IOException, MessagingException {
//pop3必须小写
URLName url = new URLName("pop3", host, port, "", user, password);
Session session = Session.getDefaultInstance(System.getProperties(),null);
Store store = session.getStore(url);
POP3Folder inbox = null;
try {
store.connect();
inbox = (POP3Folder) store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
FetchProfile profile = new FetchProfile();
profile.add(UIDFolder.FetchProfileItem.UID);
profile.add(FetchProfile.Item.ENVELOPE);
Message[] messages = inbox.getMessages();
inbox.fetch(messages, profile);
for (int i = 0; i < messages.length; i++) {
//邮件发送者
String from = decodeText(messages[i].getFrom()[0].toString());
InternetAddress ia = new InternetAddress(from);
System.out.println("FROM:"+ia.getPersonal());
//邮件发送者地址
System.out.println("FROM_ADDR:"+ia.getAddress());
//邮件标题
System.out.println("TITLE:"+messages[i].getSubject());
//邮件的唯一标识信息
System.out.println("UID:"+inbox.getUID(messages[i]));
//邮件大小
System.out.println("SIZE:"+messages[i].getSize());
//邮件发送时间
System.out.println("DATE:"+messages[i].getSentDate());
//读取邮件内容
Object content = messages[i].getContent();
if(content instanceof String)
System.out.println("CONTENT:"+content);
else
if(content instanceof Multipart)
dumpMultipart((Multipart)content);
}
} finally {
try{
inbox.close(false);
}catch(Exception e){}
try{
store.close();
}catch(Exception e){}
}
}
protected static String decodeText(String text) throws UnsupportedEncodingException{
if(text==null)
return null;
if (text.startsWith("=?GB") || text.startsWith("=?gb"))
text = MimeUtility.decodeText(text);
else
text = new String(text.getBytes("ISO8859_1"));
return text;
}
protected static void dumpMultipart(Multipart mmp) throws MessagingException, IOException{
for(int pc=0;pc<mmp.getCount();pc++){
BodyPart bp = mmp.getBodyPart(pc);
Object content = bp.getContent();
if(content instanceof String){
System.out.println("CONTENT:"+content);
}
else
if(content instanceof Multipart)
dumpMultipart((Multipart)content);
else
if(content instanceof InputStream)
System.out.println("FileName:"+decodeText(bp.getFileName()));
}
}
public static void main(String[] args) throws IOException, MessagingException {
listMails("pop3.163.com","用户名","密码");
}
}
我的jsp文件,该如何调用呢?
<%@ page contentType="text/html; charset=ISO8859_1" %>
<%@ page import="my.MailFetcher"%>
<%
MailFetcher test = new MailFetcher();
test.main();
%>
我的jsp文件,该如何调用呢?
请高手帮忙
<%@page contentType="text/html;charset=gb2312"%>
<html>
<head>
<title></title>
</head>
<body>
<jsp:useBean id="action" scope="page" class="oracle.DBAction"/>
<%
String userid = request.getParameter("userid");//获得传入的参数
if(!"".equals(userid==null?"":userid)){
action.performDel(userid); //类定义的方法,这里执行删除操作
}
%>
</body>
</html>其中class="oracle.DBAction"用来指定你的类,id="action"用来给类创建对象。