|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
首先第一点:jsp,servlet,javabean这些最基本的,嘿嘿,就算你是高手的话,在大行的企业级应用的话还是需要框架的,一个好的框架确实能构解决许多问题。用servlet将jsp文件内容转为html。用servlet将jsp文件内容转为html。代码以下:
packageexamples;
importjava.io.ByteArrayOutputStream;
importjava.io.FileOutputStream;
importjava.io.IOException;
importjava.io.OutputStreamWriter;
importjava.io.PrintWriter;
importjavax.servlet.RequestDispatcher;
importjavax.servlet.ServletContext;
importjavax.servlet.ServletException;
importjavax.servlet.ServletOutputStream;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
importjavax.servlet.http.HttpServletResponseWrapper;
publicclassToHtmlextendsHttpServlet{
privatestaticfinalStringCONTENT_TYPE="text/html;charset=GBK";
//Initializeglobalvariables
publicvoidinit()throwsServletException{
}
//ProcesstheHTTPGetrequest
publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
response.setContentType(CONTENT_TYPE);
service(request,response);
/**
*只要乐成初始化后此办法才干被挪用处置用户哀求。前一个参数供应会见初始哀求数据的办法和字段,
*后一个供应servlet机关呼应的办法。
*/
}
//ProcesstheHTTPPostrequest
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
doGet(request,response);
}
publicvoiddestroy(){
}
publicvoidservice(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
ServletContextsc=getServletContext();
Stringurl="/index.jsp";
Stringname="index.htm";//这是天生的html文件名
StringpName="e:Tomcat5.5webappsjspTohtmlindex.htm";//天生html的完全路径
RequestDispatcherrd=sc.getRequestDispatcher(url);
finalByteArrayOutputStreamos=newByteArrayOutputStream();
finalServletOutputStreamstream=newServletOutputStream(){
publicvoidwrite(byte[]data,intoffset,intlength){
os.write(data,offset,length);
}
publicvoidwrite(intb)throwsIOException{
os.write(b);
}
};
finalPrintWriterpw=newPrintWriter(newOutputStreamWriter(os));
HttpServletResponserep=newHttpServletResponseWrapper(response){
publicServletOutputStreamgetOutputStream(){
returnstream;
}
publicPrintWritergetWriter(){
returnpw;
}
};
rd.include(request,rep);
pw.flush();
FileOutputStreamfos=newFileOutputStream(pName);//把jsp输入的内容写到指定路径的htm文件中
os.writeTo(fos);
fos.close();
response.sendRedirect(name);//誊写终了后转向htm页面
}
}
在web.xml文件中设置:
<servlet><servlet-name>Tohtml</servlet-name><servlet-class>examples.ToHtml</servlet-class></servlet><servlet-mapping><servlet-name>Tohtml</servlet-name><url-pattern>/Tohtml</url-pattern></servlet-mapping>
上面是用来测试的index.jsp:
<%@pagecontentType="text/html;charset=gb2312"%><html><head><title>CacheFilterTest</title><metahttp-equiv="Content-Type"content="text/html;charset=gb2312"></head><body>复杂测试:s=<%ints=0;//mocktime-consumingcodefor(inti=0;i<1000;i++){for(intj=0;j<1000;j++){s=s+j;}}out.print(s);%></body></html>
windows系统样,他们做了什么事或者留了一些后门程序,谁都不知道,二,java开发是跨平台,任何系统上都可以运行,对于保密型系统和大型系统开发这是必要的 |
|