快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

关于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来传递内容
返回类别: 教程
上一教程: JSP读取TEXT文件
下一教程: 用缓冲技术提高JSP应用的性能和稳定性

您可以阅读与"关于JSP保存文件到服务器"相关的教程:
· 纯 jsp 操作服务器上的文本文件 [1]
· 纯 jsp 操作服务器上的文本文件 [2]
· WIN98/2000下的JSP服务器
· 让你的IIS服务器支持JSP
· SERVLET/JSP服务器端的重定向
    微笑服务 优质保证 索取样品