本文目錄一覽:
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
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/219992.html