4个回答
2013-10-22
展开全部
session.setAttribute("username",pname);
session.setAttribute("password",pword);
session.setAttribute("n_name",ppname);
session.setAttribute("n_sex",psex);
session.setAttribute("n_class",pclass); //以上几个语句用于记住当前字段,用于下面直接输出<form action="save.jsp" method="post">
如果需要保存页面信息,请点击
<input type=submit name=submit value=save>
</form>利用表单跳转到save.jsp页面save.jsp:保存的是username、password、n_name、n_class、n_sex、n_like几个字段(根据自已要输出的内容作相应修改)<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
<body>
<%
String fl=request.getParameter("submit");
if(fl!=null&&fl.equals("save")){
response.setContentType("application/msword;charset=gb2312");
out.print(session.getAttribute("username")+"<br>");
out.print(session.getAttribute("password")+"<br>");
out.print(session.getAttribute("n_name")+"<br>");
out.print(session.getAttribute("n_sex")+"<br>");
out.print(session.getAttribute("n_class")+"<br>");
}
%>
</body>
</html>
session.setAttribute("password",pword);
session.setAttribute("n_name",ppname);
session.setAttribute("n_sex",psex);
session.setAttribute("n_class",pclass); //以上几个语句用于记住当前字段,用于下面直接输出<form action="save.jsp" method="post">
如果需要保存页面信息,请点击
<input type=submit name=submit value=save>
</form>利用表单跳转到save.jsp页面save.jsp:保存的是username、password、n_name、n_class、n_sex、n_like几个字段(根据自已要输出的内容作相应修改)<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<html>
<body>
<%
String fl=request.getParameter("submit");
if(fl!=null&&fl.equals("save")){
response.setContentType("application/msword;charset=gb2312");
out.print(session.getAttribute("username")+"<br>");
out.print(session.getAttribute("password")+"<br>");
out.print(session.getAttribute("n_name")+"<br>");
out.print(session.getAttribute("n_sex")+"<br>");
out.print(session.getAttribute("n_class")+"<br>");
}
%>
</body>
</html>
博思aippt
2024-07-20 广告
2024-07-20 广告
作为深圳市博思云创科技有限公司的工作人员,对于Word文档生成PPT的操作,我们有以下建议:1. 使用另存为功能:在Word中编辑完文档后,点击文件->另存为,选择PowerPoint演示文稿(*.pptx)格式,即可将文档内容转换为PPT...
点击进入详情页
本回答由博思aippt提供
展开全部
强烈推荐用PageOffice, jsp里面在线显示、编辑word文档的神器!真正的原封原样显示在页面里。并且支持所有流行的浏览器,如IE、chrome、firefox、搜狗、360、遨游等。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-10-22
展开全部
<%@ page contentType="application/msword;charset=gb2312" language="java"%>
<%response.setHeader("Content-disposition","attachment;filename=result.doc");%>
<html>
<head>
<title>Word 输出测试</title>
</head>
<body>
<table border="1" width="100%">
<tr><td>Word 输出测试</td>
</tr>
</table>
</body>
</html> 如果想 IE不弹出保存框,去掉这行response.setHeader("Content-disposition","attachment;filename=result.doc")
<%response.setHeader("Content-disposition","attachment;filename=result.doc");%>
<html>
<head>
<title>Word 输出测试</title>
</head>
<body>
<table border="1" width="100%">
<tr><td>Word 输出测试</td>
</tr>
</table>
</body>
</html> 如果想 IE不弹出保存框,去掉这行response.setHeader("Content-disposition","attachment;filename=result.doc")
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
JAVA代码:
[java] view plaincopy
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class TransformFiletoHtml
{
int WORD_HTML = 8;
int WORD_TXT = 7;
int EXCEL_HTML = 44;
/**
* WORD转HTML
* @param docfile WORD文件全路径
* @param htmlfile 转换后HTML存放路径
*/
public void wordToHtml(String docfile, String htmlfile)
{
ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word
try
{
app.setProperty("Visible", new Variant(false));
Dispatch docs = app.getProperty("Documents").toDispatch();
Dispatch doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(WORD_HTML) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(doc, "Close", f);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
}
/**
* EXCEL转HTML
* @param xlsfile EXCEL文件全路径
* @param htmlfile 转换后HTML存放路径
*/
public void excelToHtml(String xlsfile, String htmlfile)
{
ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动excel
try
{
app.setProperty("Visible", new Variant(false));
Dispatch excels = app.getProperty("Workbooks").toDispatch();
Dispatch excel = Dispatch.invoke(excels,"Open",Dispatch.Method,new Object[] { xlsfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
}
/**
* /删除指定文件夹
* @param folderPath 文件夹全路径
* @param htmlfile 转换后HTML存放路径
*/
public void delFolder(String folderPath)
{
try
{
delAllFile(folderPath); //删除完里面所有内容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); //删除空文件夹
} catch (Exception e) {e.printStackTrace();}
}
/**
* /删除指定文件夹下所有文件
* @param path 文件全路径
*/
public boolean delAllFile(String path)
{
boolean flag = false;
File file = new File(path);
if (!file.exists())
{
return flag;
}
if (!file.isDirectory())
{
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++)
{
if (path.endsWith(File.separator))
{
temp = new File(path + tempList[i]);
}
else
{
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile())
{
temp.delete();
}
if (temp.isDirectory())
{
delAllFile(path + "/" + tempList[i]);//先删除文件夹里面的文件
delFolder(path + "/" + tempList[i]);//再删除空文件夹
flag = true;
}
}
return flag;
}
}
调用JAVA代码:
[java] view plaincopy
public class Test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
TransformFiletoHtml trans = new TransformFiletoHtml();
trans.wordToHtml("D:\\sinye.doc", "D:\\sinye.html");
}
}
[java] view plaincopy
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class TransformFiletoHtml
{
int WORD_HTML = 8;
int WORD_TXT = 7;
int EXCEL_HTML = 44;
/**
* WORD转HTML
* @param docfile WORD文件全路径
* @param htmlfile 转换后HTML存放路径
*/
public void wordToHtml(String docfile, String htmlfile)
{
ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word
try
{
app.setProperty("Visible", new Variant(false));
Dispatch docs = app.getProperty("Documents").toDispatch();
Dispatch doc = Dispatch.invoke(docs,"Open",Dispatch.Method,new Object[] { docfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(WORD_HTML) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(doc, "Close", f);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
}
/**
* EXCEL转HTML
* @param xlsfile EXCEL文件全路径
* @param htmlfile 转换后HTML存放路径
*/
public void excelToHtml(String xlsfile, String htmlfile)
{
ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动excel
try
{
app.setProperty("Visible", new Variant(false));
Dispatch excels = app.getProperty("Workbooks").toDispatch();
Dispatch excel = Dispatch.invoke(excels,"Open",Dispatch.Method,new Object[] { xlsfile, new Variant(false),new Variant(true) }, new int[1]).toDispatch();
Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] {htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
Variant f = new Variant(false);
Dispatch.call(excel, "Close", f);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
app.invoke("Quit", new Variant[] {});
}
}
/**
* /删除指定文件夹
* @param folderPath 文件夹全路径
* @param htmlfile 转换后HTML存放路径
*/
public void delFolder(String folderPath)
{
try
{
delAllFile(folderPath); //删除完里面所有内容
String filePath = folderPath;
filePath = filePath.toString();
java.io.File myFilePath = new java.io.File(filePath);
myFilePath.delete(); //删除空文件夹
} catch (Exception e) {e.printStackTrace();}
}
/**
* /删除指定文件夹下所有文件
* @param path 文件全路径
*/
public boolean delAllFile(String path)
{
boolean flag = false;
File file = new File(path);
if (!file.exists())
{
return flag;
}
if (!file.isDirectory())
{
return flag;
}
String[] tempList = file.list();
File temp = null;
for (int i = 0; i < tempList.length; i++)
{
if (path.endsWith(File.separator))
{
temp = new File(path + tempList[i]);
}
else
{
temp = new File(path + File.separator + tempList[i]);
}
if (temp.isFile())
{
temp.delete();
}
if (temp.isDirectory())
{
delAllFile(path + "/" + tempList[i]);//先删除文件夹里面的文件
delFolder(path + "/" + tempList[i]);//再删除空文件夹
flag = true;
}
}
return flag;
}
}
调用JAVA代码:
[java] view plaincopy
public class Test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
TransformFiletoHtml trans = new TransformFiletoHtml();
trans.wordToHtml("D:\\sinye.doc", "D:\\sinye.html");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询