|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
没有那个大公司会傻了吧唧用.net开发大型项目,开发了,那等于自己一半的生命线被微软握着呢。而.net不行,限制在window系统,又是捆绑,鄙视微软之!静态|静态|页面1.媒介为了能深切浅出的了解这个框架的由来,我们起首来懂得一下JSP剖析器将我们写的JSP代码转换成的JAVA文件的内容。上面是一个JSP文件test.jsp<%@pagelanguage=javacontentType=text/html;charset=GB2312%><%out.write();%><%=输入%>经由TOMCAT转换出的JAVA文件test$jsp.java内容以下:packageorg.apache.jsp;importjavax.servlet.*;importjavax.servlet.http.*;importjavax.servlet.jsp.*;importorg.apache.jasper.runtime.*;publicclasstest$jspextendsHttpJspBase{static{}publictestOutRedir$jsp(){}privatestaticboolean_jspx_inited=false;publicfinalvoid_jspx_init()throwsorg.apache.jasper.runtime.JspException{}publicvoid_jspService(HttpServletRequestrequest,HttpServletResponseresponse)throwsjava.io.IOException,ServletException{JspFactory_jspxFactory=null;PageContextpageContext=null;HttpSessionsession=null;ServletContextapplication=null;ServletConfigconfig=null;JspWriterout=null;Objectpage=this;String_value=null;try{if(_jspx_inited==false){synchronized(this){if(_jspx_inited==false){_jspx_init();_jspx_inited=true;}}}_jspxFactory=JspFactory.getDefaultFactory();response.setContentType(text/html;charset=GB2312);pageContext=_jspxFactory.getPageContext(this,request,response,,true,8192,true);application=pageContext.getServletContext();config=pageContext.getServletConfig();session=pageContext.getSession();out=pageContext.getOut();//为了节俭篇幅,我删除注释器增加的正文out.write(
);//上一句是因为<%@pagelanguage=javacontentType=text/html;charset=GB2312%>前面的换行发生的out.write();out.write(
);out.print(输入);out.write(
);}catch(Throwablet){if(out!=null&&out.getBufferSize()!=0)out.clearBuffer();if(pageContext!=null)pageContext.handlePageException(t);}finally{if(_jspxFactory!=null)_jspxFactory.releasePageContext(pageContext);}}}从下面的代码中能够明晰的看到JSP内建的几个对象(out、request、response、session、pageContext、application、config、page)是怎样发生的,懂servlet的伴侣一看就可以分明。上面重点了解一下out对象,它被声明为JspWriter范例,JspWriter是一个笼统类,在包javax.servlet.jsp中能够找到它的界说。abstractpublicclassjavax.servlet.jsp.JspWriterextendsjava.io.Writer{finalpublicstaticintNO_BUFFER=0;finalpublicstaticintDEFAULT_BUFFER=-1;finalpublicstaticintUNBOUNDED_BUFFER=-2;protectedintbufferSize;protectedBooleanautoFlush;protectedjavax.servlet.jsp.JspWriter(intarg1,booleanarg2);abstractpublicvoidnewLine()throwsIOException;abstractpublicvoidprint(booleanarg0)throwsIOException;abstractpublicvoidprint(chararg0)throwsIOException;abstractpublicvoidprint(intarg0)throwsIOException;abstractpublicvoidprint(longarg0)throwsIOException;abstractpublicvoidprint(floatarg0)throwsIOException;abstractpublicvoidprint(doublearg0)throwsIOException;abstractpublicvoidprint(char[]arg0)throwsIOException;abstractpublicvoidprint(Stringarg0)throwsIOException;abstractpublicvoidprint(Objectarg0)throwsIOException;abstractpublicvoidprintln()throwsIOException;abstractpublicvoidprintln(booleanarg0)throwsIOException;abstractpublicvoidprintln(chararg0)throwsIOException;abstractpublicvoidprintln(intarg0)throwsIOException;abstractpublicvoidprintln(longarg0)throwsIOException;abstractpublicvoidprintln(floatarg0)throwsIOException;abstractpublicvoidprintln(doublearg0)throwsIOException;abstractpublicvoidprintln(char[]arg0)throwsIOException;abstractpublicvoidprintln(Stringarg0)throwsIOException;abtractpublicvoidprintln(Objectarg0)throwsIOException;abstractpublicvoidclear()throwsIOException;abstractpublicvoidclearBuffer()throwsIOException;abstractpublicvoidflush()throwsIOException;abstractpublicvoidclose()throwsIOException;publicintgetBufferSize();abstractpublicintgetRemaining();publicbooleanisAutoFlush();}我信任当我写到这里你大概已晓得我想怎样做了。是的,来个批红判白,承继JspWriter类,然后完成其界说的虚函数,然后把out变量交换成你本人完成的类的实例就ok了。2.完成交换假定<%@pagelanguage=javacontentType=text/html;charset=GB2312import=jwb.util.HtmlIntoFile,jwb.util.TempSinglet,java.io.File%><%JspWriterout_bak=out;Stringarg1=argument1;StringfilePath=/cache/依据参数天生文件名_+arg1+.html;//起首判别文件是不是已存在,假如不存在则实行本页面,不然跳转到静态页面就OK了Filef=newFile(pageContext.getServletContext().getRealPath(filePath));if(f.exists()){out_bak.clear();pageContext.forward(filePath);System.out.println(间接转到静态页面);return;}out=newHtmlIntoFile(pageContext.getServletContext().getRealPath(filePath));out.write();%><%=看吧,这就是输入被重定向到文件的完成,很复杂吧^_^%><%out.close();//封闭天生的静态文件out_bak.clear();pageContext.forward(filePath);System.out.println(实行本页面后再转到静态页面);return;%>3.更新成绩上面就会商一下怎样更重生成静态文件,实在从下面完成中你能够看到,很复杂的就是将天生的静态文件删除便可,至于甚么时分删除,要看你的需求了。我能想到的几种情形以下
- 当用来天生页面的数据更新时
- 假如不必要很供应不时的数据能够准时更新
- 永久不更新
有了这样一个呼声:让java代替C语言成为基本语言。这些足以说明java简单易学的这个优点。其次,java的功能强大,前面我也提到了,EJB3.0的推出使java成为了大型项目的首选。 |
|