| 网站首页 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛 |
 
 
 
您现在的位置: 编程中国 >> 技术教程 >> Web开发 >> JSP >> JSP技术资料 >> 正文
  ►  JSP问答
JSP问答
作者:佚名    阅读人次:……    文章来源:不详    发布时间:2004-10-8    网友评论()条
 




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 "); 
%> 
<%= howBadFrom(request) %> 


12、如果BROWSER已关闭了COOKIES,在JSP中我如何打开SESSION来跟踪 
使用URL重写即可,如下: 
hello1.jsp 
<%@ page session="true" %> 
<% 
Integer num = new Integer(100); 
session.putValue("num",num); 
String url =response.encodeURL("hello2.jsp"); 
%> 
<a href=<%=url%>>hello2.jsp</a> 

hello2.jsp 
<%@ page session="true" %> 
<% 
Integer i= (Integer )session.getValue("num"); 
out.println("Num value in session is "+i.intValue()); 
%> 


13、在JSP中能发送EMAIL吗 
可以使用SUN的专用包:sun.net.smtp包。如下脚本使用SmtpClient类发送EMAIL。 
<%@ page import="sun.net.smtp.SmtpClient, java.io.*" %> 
<% 
String from="ybwen@sina.com"; 
String to="hewenjun@yeah.net, lei@who.com.cn"; 
try{ 
SmtpClient client = new SmtpClient("mail.xxxxx.xxx"); 
client.from(from); 
client.to(to); 
PrintStream message = client.startMessage(); 
message.println("To: " + to); 
message.println("Subject: Sending email from JSP!"); 
message.println("This was sent from a JSP page!"); 
message.println(); 
message.println("Cool! :-)"); 
message.println(); 
message.println("Good Boy"); 
message.println("Im in genius.com"); 
message.println(); 
client.closeServer(); 

catch (IOException e){ 
System.out.println("ERROR SENDING EMAIL:"+e); 

%> 

上一页  [1] [2] [3] [4] [5] 下一页

 

 
文章录入:静夜思    责任编辑:静夜思 
  • 上一篇文章: 没有了

  • 下一篇文章:

  •  
    相关文章
    原创地带
    24小时热门帖子