首页 > 编程知识 正文

jsp收藏完整代码,jsp笔记

时间:2023-12-29 20:32:01 阅读:331057 作者:KKWF

本文目录一览:

JSP如何实现 网页收藏 功能 在网页添加一个按钮 要求用户点击该按钮 可以将本网页添加到收藏夹 如何实现

a href="#" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('');return(false);" 设为首页/a | a href="javascript:window.external.AddFavorite('','百度一下')" 加入收藏/a

jsp上传图片,最好完整代码。100分!

upfile.jsp 文件代码如下:

form method="post" action="uploadimage.jsp" name="form1" enctype="multipart/form-data"

input type="file" name="file"

input type="submIT" name="sub" value="upload"

/form

form method="post" action="uploadimage.jsp" name="form1" enctype="multipart/form-data"

input type="file" name="file"

input type="submit" name="sub" value="upload"

/form

STRONGFONT color=#ff0000uploadimage.jsp/FONT/STRONG

文件代码如下:

uploadimage.jsp

文件代码如下:view plaincopy to clipboardprint?

PRE class=java name="code"%@ page language="java" pageEncoding="gb2312"%

%@ page import="java.io.*,java.awt.Image,java.awt.image.*,com.sun.image.codec.jpeg.*,java.sql.*,com.jspsmart.upload.*,java.util.*"%

%@ page import="mainClass.*" %

html

head

titleMy JSP 'uploadimage.jsp' starting page/title

/head

body

%

SmartUpload sma=new SmartUpload();

long file_max_size=4000000;

String filename1="",ext="",testvar="";

String url="uploadfiles/";

sma.initialize(pageContext);

try

{

sma.setAllowedFilesList("jpg,gif");

sma.upload();

}catch(Exception e){

%

script language="jscript"

alert("只允许上传jpg,gif图片")

window.location.href="upfile.jsp"

/script

%

}

try{

com.jspsmart.upload.File myf=sma.getFiles().getFile(0);

if(myf.isMissing()){

%

script language="jscript"

alert("请选择要上传的文件!")

window.location.href="upfile.jsp"

/script

%

}else{

ext=myf.getFileExt();

int file_size=myf.getSize();

String saveurl="";

if(file_size file_max_size){

Calendar cal=Calendar.getInstance();

String filename=String.valueOf(cal.getTimeInMillis());

saveurl=request.getRealPath("/")+url;

saveurl+=filename+"."+ext;

myf.saveAs(saveurl,sma.SAVE_PHYSICAL);

myclass mc=new myclass(request.getRealPath("data/data.mdb"));

mc.executeInsert("insert into [path] values('uploadfiles/"+filename+"."+ext+"')");

out.println("图片上传成功!");

response.sendRedirect("showimg.jsp");

}

}

}catch(Exception e){

e.printStackTrace();

}

%

/body

/html

/PRE

本文来自: IT知道网() 详细出处参考:

如何用jsp代码把当前页设置为主页

将下面代码嵌入你的jsp body中想设为主页的位置:

a href=# onClick="this.style.behavior='url(#default#homepage)';this.setHomePage(‘你的网址’);"设为首页/a

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。