Ö´ÐÐ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() {
Ïà¹ØÎĵµ£º
ºÜ¶àÈ˺öÊÓÁËHTML±êÇ©METAµÄÇ¿´ó¹¦Ð§£¬Ò»¸öºÃµÄMETA±êÇ©Éè¼Æ¿ÉÒÔ´ó´óÌá¸ßÄãµÄ¸öÈËÍøÕ¾±»ËÑË÷µ½µÄ¿ÉÄÜÐÔ£¬ÓÐÐËȤÂð£¬ËÎÒÀ´ÖØÐÂÈÏʶһÏÂMETA±êÇ©°É£¡
META±êÇ©ÊÇHTMLÓïÑÔHEADÇøµÄÒ»¸ö¸¨ÖúÐÔ±êÇ©£¬ËüλÓÚHTMLÎĵµÍ·²¿µÄ<HEAD>±ê¼ÇºÍ<TITLE>±ê¼Ç
Ö®¼ä£¬ËüÌṩÓû§²»¿É¼ûµÄÐÅÏ¢¡£meta±êǩͨ³£ÓÃÀ´ÎªËÑË÷ÒýÇærobo ......
1 javascript £¬ÉèÖÃÒ»¸ö±äÁ¿£¬Ö»ÔÊÐíÌá½»Ò»´Î¡£
2 »¹ÊÇjavascript£¬½«Ìá½»°´Å¥»òÕßimageÖÃΪdisable
onsubmit="getElById('submitInput').disabled = true; return true;">
3 ÀûÓÃstrutsµÄͬ²½ÁîÅÆ»úÖÆ
......
JSPÒ³ÃæÖÐÒ»°ãÓÐÁ½Àà×¢ÊÍ
1.html×¢ÊÍ
ÐÎÈç<!--...................-->
Ëü»áͬhtml±ê¼Çһͬ·¢µ½¿Í»§¶Ë
2.jsp×¢ÊÍ£¨3ÖÖ£©
ÐÎÈç<%--.............................--%>
Ëü²»»á±»·¢Ë͵½¿Í»§¶Ë£¬Ö»ÓÃÀ´×¢ÊÍ·þÎñÆ÷¶ËµÄjspÎļþ£¬Á¬jspÉú³ÉµÄservletҲûÓÐ×¢ÊͽøÈ¥£¬ÕâÒ²ÊǴ󲿷ÖÈËʹÓõÄ×¢ÊÍ
ÐÎÈç<%//...... ......
¿ÉÄÜ´ó¶àÊýJsp¿ª·¢Ô±ÔÚдÍê³ÌÐò²âÊÔͨ¹ýºó£¬²»Ì«»á¹Ø×¢JspÉú³ÉµÄJavaÎļþ£¬Æäʵ£¬Í¨¹ýJava´úÂ룬¸üÄÜÌåÏÖ³ÌÐò´úÂëµÄÕæÕýº¬Ò壬¶Ô½øÒ»²½Ñо¿³ÌÐò´úÂëµÄºǫ́ÔËÐÐÇé¿öÊǷdz£ÓаïÖúµÄ¡£ÀýÈ磬ÓÃJsp±àд´úÂëʱ£¬ÓÐʱºòÓÃ<%! %>£¬ÓÐʱºòÓÃ<% %>£¬¼Ó²»¼Ó¸Ð̾º ......
ÎÒÃǶ¼ÖªµÀÔÚjspÖÐincludeÓÐÁ½ÖÖÐÎʽ,·Ö±ðÊÇ
<%@ include file=" "%>
<jsp:include page=" " flush="true"/>
Ç°ÕßÊÇÖ¸ÁîÔªËØ¡¢ºóÕßÊÇÐÐΪԪËØ.
ͨ³£µ±Ó¦ÓóÌÐòÖÐËùÓеÄÒ³ÃæµÄijЩ²¿·Ö(ÀýÈç±êÌâ¡¢Ò³½ÅºÍµ¼º½À¸)¶¼ÏàͬµÄʱºò,Î ......