好文档 - 专业文书写作范文服务资料分享网站

JSP入门教程

天下 分享 时间: 加入收藏 我要投稿 点赞

out.println(\out.flush(); }

public void doPost(HttpServletRequest req, HttpServletResponse ServletException,IOException {

resp.setContentType(\

PrintWriter out = new PrintWriter(resp.getOutputStream()); String from = req.getParameter(MAIL_FROM); String to = req.getParameter(MAIL_TO);

String subject = req.getParameter(MAIL_SUBJECT); String body = req.getParameter(MAIL_BODY); String mailhost = req.getParameter(MAIL_HOST); try {

SmtpClient mailer = new SmtpClient(mailhost); mailer.from(from); mailer.to(to);

PrintStream ps = mailer.startMessage(); ps.println(\ps.println(\

ps.println(\ ps.println(body); mailer.closeServer(); out.println(\ }

catch (Exception ex) {

out.println(\ }

out.flush(); }

public void init(ServletConfig cfg) throws ServletException {

super.init(cfg); }

public void destroy() {

super.destroy(); } }

resp) throws

14. 简单的“抓网页”代码

作者:东方一蛇/我的家

一、前言

从一个网站上,看到一个“抓网页”的代码,觉得有点意思,但是没有提供源代码,于是,自己想写一个,其实代码比较简单的。 二、代码

<%@ page contentType=\ <%

String sCurrentLine; String sTotalString; sCurrentLine=\ sTotalString=\

java.io.InputStream l_urlStream;

java.net.URL l_url = new java.net.URL(\ java.net.HttpURLConnection l_connection = (java.net.HttpURLConnection) l_url.openConnection(); l_connection.connect();

l_urlStream = l_connection.getInputStream(); java.io.BufferedReader l_reader = new java.io.BufferedReader(new java.io.InputStreamReader(l_urlStream));

while ((sCurrentLine = l_reader.readLine()) != null) {

sTotalString+=sCurrentLine; }

out.println(sTotalString); %>

三、后记

虽然代码比较简单,但是,我认为根据这个,可以实现“网络爬虫”的功能,比如从页面找href连接,然后再得到那个连接,然后再“抓”,不停止地(当然可以限定层数),这样,可以实现“网页搜索”功能。

15. JSP生成jpeg图片用于投票

作者:东方一蛇/我的家

一、前言

本文原作者为Tony Wang ,该文章涉及到文件的读写和jpg图片的自动生成。利用jsp+servlet的技术,jsp调用servlet生成图片。 二、首文件index.jsp如下:

<%--

Author: Tony Wang

E-mail: lucky_tony@163.net Date: 2001-01-01

如果对程序有什么疑问,可以和我联系, 另外程序如果有什么bug,麻烦指出!! --%>

<%@ page contentType=\<%

response.setHeader(\response.setDateHeader(\%> <%!

public String[] getQuestion(String s) {

String[] strQ = new String[4]; String strTemp = null; int i;

java.io.RandomAccessFile rf = null; try {

rf = new java.io.RandomAccessFile(s,\} catch(Exception e) {

System.out.println(e); System.exit(0); }

for(i=0;i<4;i++) { try {

strTemp = rf.readLine(); } catch(Exception e) {

strTemp = \}

if(strTemp==null)strTemp = \strQ[i] = strTemp; }

return strQ; } %> <%

String s = null;

String[] question = new String[4];

s = request.getRealPath(\question = getQuestion(s); %>

冰帆调查
<%

String ss = null; for (int i=0;i<4;i++) {

ss = \(char)('A'+i)+\、\out.println(ss); } %>

三、写文件write.jsp <%--

Author: Tony Wang

E-mail: lucky_tony@163.net Date: 2001-01-01

如果对程序有什么疑问,可以和我联系, 另外程序如果有什么bug,麻烦指出!!

--%> <%!

public int[] getNumber(String s) {

int[] mCount = new int[4]; String strTemp = null; int i;

java.io.RandomAccessFile rf = null; try {

rf = new java.io.RandomAccessFile(s,\} catch(Exception e) {

System.out.println(e); System.exit(0); }

for(i=0;i<4;i++) { try {

strTemp = rf.readLine(); } catch(Exception e) { strTemp = \}

if(strTemp==null)strTemp = \

mCount[i] = new Integer(strTemp).intValue(); }

return mCount; }

public void setNumber(String s,int[] x) { try {

java.io.PrintWriter pw = new java.io.PrintWriter(new java.io. FileOutputStream(s)); for (int i=0;i<4;i++){ pw.println(x[i]+\}

pw.close();

} catch(Exception e) {

System.out.println(\} } %> <%

String tmp = null;

JSP入门教程

out.println(\out.flush();}publicvoiddoPost(HttpServletRequestreq,HttpServletResponseServletException,IOException{resp.setContentType(\PrintWriterout=newPrintWr
推荐度:
点击下载文档文档为doc格式
3d3ov3v4f03ibqw7sila
领取福利

微信扫码领取福利

微信扫码分享