|
|
1、如何混合使用Jsp和SSI #include?
在JSP中可以使用如下方式包含纯HTML:
<!--#include file="data.inc"-->
但是如果data.inc中包含JSP CODE ,我们可以使用:
<%@include file="data.inc"%> 字串9
2、如何执行一个线程安全的JSP?
只需增加如下指令
<%@ page isThreadSafe="false" %> 字串3
3、JSP如何处理HTML FORM中的数据?
通过内置的request对象即可,如下:
<%
String item = request.getParameter("item");
int howMany = new Integer(request.getParameter("units")).intValue();
%>
字串7
4、在JSP如何包含一个静态文件?
静态包含如下:<%@ include file="copyright.html" %>
动态包含如下:<jsp:include page="copyright.html" flush="true"/> 字串4
5、在JSP中如何使用注释?
主要有四中方法:
1。<%-- 与 --%>
2。//
3。/**与**/
4。<!--与--> 字串2
6、在JSP中如何执行浏览重定向?
使用如下方式即可:response.sendRedirect("http://ybwen.home.chinaren.com/index.html");
也能物理地改变HTTP HEADER属性,如下:
<%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn="/newpath/index.html";
response.setHeader("Location",newLocn);
%> 字串7
7、如何防止在JSP或SERVLET中的输出不被BROWSER保存在CACHE中?
把如下脚本加入到JSP文件的开始即可:
<%
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%> 字串3
8、在JSP中如何设置COOKIE?
COOKIE是作为HTTP HEADER的一部分被发送的,如下方法即可设置:
<%
Cookie mycookie = new Cookie("aName","aValue");
response.addCookie(mycookie);
%> 字串1
9、在JSP中如何删除一个COOKIE?
<%
Cookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.setMaxAge(0);
killMyCookie.setPath("/");
response.addCookie(killMyCookie);
%> 字串8
10、在一个JSP的请求处理中如何停止JSP的执行
如下例:
<%
if (request.getParameter("wen") != null) {
// do something
} else {
return;
}
%>
<div class="Syc482">字串4 |
|