首页  电脑故障排除  病毒安全 电脑基础知识  硬件知识  软件应用知识  操作系统知识  编程程序

美国编程网址 日本编程网址 法国编程网址 德国编程网址 韩国编程网址 香港编程网址 台湾编程网址

您的位置:首页>>编程程序>>JSP

关于jsp保存文件到服务器 关于jsp保存文件到服务器

 
关于jsp保存文件到服务器 关于jsp保存文件到服务器


<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>

<%@ page import="org.omg.CORBA.Object.*" %>
<%@ page import="javax.servlet.ServletRequest.*" %>
<%@ page import="javax.servlet.*" %>
<html>
<head>


<title>在HTML中调用XML数据</title>
</head>
<body bgcolor="#FFFFFF">

<%!
public String savexml(String textxml){
String guestbookpath=getServletContext().getRealPath("/jspsave.jsp");
try{
java.io.FileWriter fw=new java.io.FileWriter(guestbookpath+"\guestbook.txt",true);
java.io.PrintWriter pw=new java.io.PrintWriter(fw);

pw.println(textxml);
pw.close();
fw.close();
System.out.println(textxml);
return null;
}
catch(Exception e){
// out.println(e.getMessage());
}
return null;
}

%>

<form name="form1" method="post" action="savexml(document.form1.xmltext.value)" >
<textarea name="xmltext" cols="80" rows="30"></textarea>
<input type="button" name="Submit" value="提交" onClick="savexml(document.form1.xmltext.value)" >
</form>
</body>
</html>

---------------------------------------------------------------

//上传的例子
<%@ page contentType="text/html; charset=gb2312" buffer="1" autoFlush="true"%>

<%@ page import="com.jspsmart.upload.*" %>
<body>

<%
SmartUpload upload = new SmartUpload();
upload.initialize(pageContext);
upload.upload();
for (int i=0;i<upload.getFiles().getCount();i++){
com.jspsmart.upload.File newFile = upload.getFiles().getFile(i);

if (!newFile.isMissing()) {

newFile.saveAs("d:/websrc/upload/" + newFile.getFileName());//修改你的存储路径
out.println("FieldName = " + newFile.getFieldName() + "<BR>");
out.println("Size = " + newFile.getSize() + "<BR>");
out.println("FileName = " + newFile.getFileName() + "<BR>");
out.println("FileExt = " + newFile.getFileExt() + "<BR>");
out.println("FilePathName = " + newFile.getFilePathName() + "<BR>");
out.println("ContentType = " + newFile.getContentType() + "<BR>");
out.println("ContentDisp = " + newFile.getContentDisp() + "<BR>");
out.println("TypeMIME = " + newFile.getTypeMIME() + "<BR>");
out.println("SubTypeMIME = " + newFile.getSubTypeMIME() + "<BR>");

}

}
%>
</body>
---------------------------------------------------------------

什么错误啊!粘出来
---------------------------------------------------------------

是javaScript的错把。你的onclick方法里面调用了savexml方法,而savexml没有定义(你现在定义的是jsp脚本里面的savexml方法)。
---------------------------------------------------------------

lileinlp(目空一切) onclick当然不能调用jsp脚本里面的savexml方法,java代码在页面初始化后,就不存在了,onclick只能调用js 写的函数
---------------------------------------------------------------



你应该把保存文件的功能方到另一个jsp文件里,通过request来传递内容


查看上一页  返回分类首页 返回96PC首页  查看下一页

  版权所有:电脑知识大全 网站备案:粤ICP备07031496号  联系我们

友情链接:母婴知识  外贸商务网  娱乐频道  汽车维修知识  股票入门知识  游戏攻略秘籍  本站空间由安信网络提供