执行JSP后生成HTML静态文件
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
public class toHtml extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String url="";
String name="";
ServletContext sc = getServletContext();
//你要访问的jsp文件,如index.jsp
//则你访问这个servlet时加参数.
//如http://localhost/toHtml?file_name=index
String file_name=request.getParameter("file_name");
//这是你要生成HTML的jsp文件,如
//http://localhost/index.jsp的执行结果.
url = "/"+file_name+".jsp";
//这是生成的html文件名,如index.htm.
name="/home/resin/resin-2.1.6/doc/"+file_name+".htm";
RequestDispatcher rd = sc.getRequestDispatcher(url);
final ByteArrayOutputStream os = new ByteArrayOutputStream();
final ServletOutputStream stream = new ServletOutputStream() {
public void write(byte[] data, int offset, int length) {
os.write(data, offset, length);
}
public void write(int b) throws IOException {
os.write(b);
}
};
final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));
HttpServletResponse rep = new HttpServletResponseWrapper(response) {
public ServletOutputStream getOutputStream() {
相关文档:
js的方法:
if(document.getElementById('example')) {
// do something
}
else {
// do something else
}
jquery的方法:
if($('#example').length) {
......
package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
im ......
JSP页面的三类基本元素
1.声明
形如
<%!
int a;
int add(int a,int b)
{
return a+b;
......
最近需要将xml的数据提取出来转化为xml,因此上网找资料搜索了一番,也学到了很多。现将学习时写的代码和文件发上来,记录记录,以备忘。
首先贴一下xml文件的代码。
<?xml version="1.0"?>
<students>
<student id="1001">
<name>张三</name>
<score>85</score&g ......
文章类型:技术文档 更新时间:2009-03-03 发布者:HIT-ASP 文章来源:HIT-ASP 点击次数:550
摘自:
http://www.zzsky.cn/build/content/658.htm
http://www.blueidea.com/tech/multimedia/2 ......