📄 skill1.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="KEYWORDS" content="小龙亭工作室之JSP实践之旅">
<title>小龙亭工作室之JSP实践之旅</title>
<link rel="stylesheet" href="../jsp.css" type="text/css">
</head>
<body topmargin="0" leftmargin="0" rightmargin="0">
<div align="center"><!--以下开始小龙亭标题 -->
<script language="javascript" src="../gaptitle.js"></script>
<!--以下开始主题索引td和文章区td -->
<div
align="center"><center>
<table width="100%">
<tr>
<td colspan="2" height="10"></td>
</tr>
<tr>
<td width="20%" style="border-right: 1px solid red" valign="top" height="227"><script
language="javascript" src="manualindex.js"></script> </td>
<td width="80%" valign="top" height="227">
<p align="center"><b><font size="3" color="#FF0000">JSP技巧集锦(一)</font></b></p>
<p> </p>
<p><font color="#0000FF">(Blueski整理编辑)</font></p>
<hr width="95%" color=#ff00ff noshade size=1>
<p><b>网页重定向<br>
</b>
<br>
1 可以使用:
<p>response.sendRedirect("http://www.foo.com/path/error.html");<br>
<p>2 你可以手工修改HTTP header的Location属性,如下:<br>
<%<br>
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);<br>
String newLocn = "/newpath/index.html";<br>
response.setHeader("Location",newLocn);<br>
%><br>
<br>
3 也可以使用forward:
<p><jsp:forward page="/newpage.jsp" />
<p><br>
请注意你只能在任何输出还没有发送到客户端之前使用这种方式。
<hr width="95%" color=#ff00ff noshade size=1>
<p><b>
在JSP页中如何设置cookie?<br>
</b>
<p>
以下scriptlet在客户端设置了一个cookie "mycookie": <br>
<%<br>
Cookie mycookie = new Cookie("aName","aValue");<br>
response.addCookie(mycookie);<br>
%><br>
通常,cookies在JSP页的开始处进行设置,因为它们作为HTTP headers的一部分被送出。 <br>
如果你想在关闭浏览器后在cookie中保存数据,你还需要设置expiration date,例如,<br>
cookie_name.setMaxAge( time_in_milisecs ); <br>
<br>
<hr width="95%" color=#ff00ff noshade size=1>
<p><b>
中途退出<br>
</b>
<p>
<% <br>
if (request.getParameter("foo") != null) {<br>
// generate some html or update bean property <br>
} else {<br>
<br>
/* output some error message or provide redirection <br>
back to the input form after creating a memento <br>
bean updated with the 'valid' form elements that were input.<br>
this bean can now be used by the previous form to initialize <br>
the input elements that were valid<br>
then, return from the body of the _jspService() method to <br>
terminate further processing */<br>
<br>
return;<br>
}<br>
%><br>
<hr width="95%" color=#ff00ff noshade size=1>
<p>
<br>
<b>
在servlet和JSP之间共享session<br>
</b>
<br>
这很简单。JSP可以比较简单地创建session对象并使之有效。<br>
在servlet中你要手工做这些工作: <br>
HttpSession session = request.getSession(true); //如果还没有则创建一个session <br>
session.putValue("variable","value");//对session变量赋值。<br>
<br>
在jsp中可以这样取得session值: <br>
<%<br>
session.getValue("varible");<br>
%><br>
<hr width="95%" color=#ff00ff noshade size=1>
<p>
<br>
<b>类似global.asa的做法<br>
</b>
<br>
在JSP中没有global.asa的对应物。但你可以有一个workaround来运行。例如,如果你需要存储或存取<br>
application scope变量,你总是可以创建一个javabean,并在页面中需要这些变量的地方将它包含进来。 <br>
<jsp:useBean id="globals" scope="application" class="com.xxx.GlobalBean"/> <br>
<br>
但是,也有一些产品具有这样的对应:<br>
Allaire公司的产品JRun 3.0将提供global.jsa。JRun 2.x也有global.jsa特性来<br>
to aid the cross-over crowd from ASP.<br>
JRun 2.3.3仍然给予支持,但只对JSP 0.92。当JRun 3.0最终推出时它将支持用于JSP 1.0和1.1的global.jsa。<br>
你可以从http://beta.allaire.com/jrun30得到JRun 3.0 beta 5 (04/05/2000)。 <br>
另外,Oracle的JSP支持globals.jsa。 <br>
<hr width="95%" color=#ff00ff noshade size=1>
</td>
</tr>
<!-- 以下是底边-->
<script language="javascript" src="../gapbottom.js"></script>
</center>
</body>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -