动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Jsp → 阅读文章

 Jsp如何实现网页的重定向

作者来源: 
阅读 1255 人次 , 2006-3-29 4:23:00 


  1.可以使用:

  response.sendredirect("http://www.foo.com/path/error.html");

  2.可以手工修改http header的location属性,如下:

<%
response.setstatus(httpservletresponse.sc_moved_permanently);
string newlocn = "/newpath/index.html";
response.setheader("location",newlocn);
%>

  3.也可以使用forward:

  <jsp:forward page="/newpage.jsp" />

  请注意:只能在任何输出还没有发送到客户端之前使用这种方式。

  5.6 类似global.asa的做法

  在jsp中没有global.asa的对应物。但可以有一个workaround来运行。例如,如果你需要存储或存取application scope变量,你总是可以创建一个javabean,并在页面中需要这些变量的地方将它包含进来。

<jsp:usebean id="globals" scope="application" class="com.xxx.globalbean"/>

  但是,也有一些产品具有这样的对应:

  allaire公司的产品jrun 3.0将提供global.jsa。jrun 2.3.3仍然给予支持,但只对jsp 0.92。当jrun 3.0最终推出时它将支持用于jsp 1.0和1.1的global.jsa。

  你可以从http://beta.allaire.com/jrun30得到jrun 3.0 beta 5

  另外,oracle的jsp支持globals.jsa。

  5.7 jsp显示当前时间

<%@ page import="java.util.*, java.text.*" %>
<html>
<head>
<title>jsp to display the current time</title>
</head>
<body>
the current time is:
<%
date now = new date();
out.println(dateformat.gettimeinstance().format(now));
%>
</body>
</html>

  5.8在jsp中创建目录 mkdir(string path)

<%@ page import="java.io.*" %>
<%!
string mkdir(string path)
{
string msg=null;
java.io.file dir;

// 新建文件对象
dir =new java.io.file(path);
if (dir == null) {
msg = "错误原因:<br>对不起,不能创建空目录!";
return msg;
}
    if (dir.isfile()) {
    msg = "错误原因:<br>已有同名文件<b>" + dir.getabsolutepath() + "</b>存在。";
    return msg;
    }
    if (!dir.exists())
{
    boolean result = dir.mkdirs();
        if (result == false) {
    msg = "错误原因:<br>目录<b>" + dir.getabsolutepath() + "</b>创建失败,原因不明!";
        return msg;
    }
   // 如果成功创建目录,则无输出。
    // msg ="成功创建目录: <b>" + dir.getabsolutepath() + "</b>";
    return msg;
    }
  else {
      msg = "错误原因:<br>目录<b>" + dir.getabsolutepath() + "</b>已存在。";
    }
  return msg;
}
%>
<%
string filepath = "/usr/home/hoyi/html/dir";
string opmsg = mkdir(filepath);
%>

  5.9将return 转为<br>函数

public static string returntobr(string sstr)
{
if (sstr == null // sstr.equals(""))
{
return sstr;
}

string stmp = new string();
int i = 0;

while (i <= sstr.length()-1)
{
if (sstr.charat(i) == '\n')
{
stmp = stmp.concat("<br>");
}
else
{
stmp = stmp.concat(sstr.substring(i,i+1));
}
i++;
}
return stmp;
}

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:通过JSP的预编译消除性能瓶颈
· 下一篇:jsp连接数据库大全
· JSP由浅入深(8)
· 浏览器关闭cookie情况下进行会话管理
· 如何使用JSP连接DB2数据库
· JSP技术生成动态web页面
· JAVA/JSP学习系列之三(Resin+Apache的安装)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077