JSP问答集
1、如何混合使用Jsp和SSI #include?
在JSP中可以使用如下方式包含纯HTML:
但是如果data.inc中包含JSP CODE ,我们可以使用:
2、如何执行一个线程安全的JSP?
只需增加如下指令
3、JSP如何处理HTML FORM中的数据?
通过内置的request对象即可,如下:
String item = request.getParameter("item");
int howMany = new Integer(request.getParameter("units")).intValue();
4、在JSP如何包含一个静态文件?
静态包含如下:
动态包含如下:
5、在JSP中如何使用注释?
主要有四中方法:
1。
2。//
3。/**与**/
4。
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、如何防止在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
8、在JSP中如何设置COOKIE?
COOKIE是作为HTTP HEADER的一部分被发送的,如下方法即可设置:
Cookie mycookie = new Cookie("aName","aValue");
response.addCookie(mycookie);
9、在JSP中如何删除一个COOKIE?
Cookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.setMaxAge(0);
killMyCookie.setPath("/");
response.addCookie(killMyCookie);
10、在一个JSP的请求处理中如何停止JSP的执行
如下例:
if (request.getParameter("wen") != null) {
// do something
} else {
return;
}
11、在JSP中如何定义方法
你可以定义方法,但是你不能直接访问JSP的内置对象,而是通过参数的方法传递。如下:
public String howBadfrom(HttpServletRequest req) {
HttpSession ses = req.getSession();
...
return req.getRemoteHost();
}
out.print("in general,lao lee is not baddie ");
12、如果BROWSER已关闭了COOKIES,在JSP中我如何打开SESSION来跟踪
使用URL重写即可,如下:
hello1.jsp
Int
相关文档:
第一种:
就是直接给出下载的地址,这种方式很不好,因为会暴露你的地址,带来很多不安全的因素,可以说是千万不要用这种
第二种:
下载页面
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<html>
<head>
<title>download</title>
</head>
< ......
JSP中的COOKIE操作
Cookie概念:
Cookie的格式实际上是一段纯文本信息, 由服务器随着网页一起发送到客户端, 并保存在客户端硬盘中指定的目录的. 大家都传说Cookie会造成严重的安全威胁什么的, 其实不是这么回事情. 服务器读取Cookie的时候, 只能够读取到这个服务 ......
http:/localhost/123/jsp/test.jsp:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logi ......
·pageContext:提供对页面属性的访问。
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("basePath",basePath);
%>
使用:
${pageScope}
·reques ......