软件艺术思考者  
混沌,彷徨,立志,蓄势...
公告
日历
<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

随笔分类(86)

随笔档案(85)

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 
使用response.sendRedirect()地址栏将改变
使用request.getRequestDispatcher().forward(request,response)地址栏中的信息保持不变只用通过方法2跳转 才能在新页取出来

redirect 会首先发一个response给浏览器, 然后浏览器收到这个response后再发一个requeset给服务器, 然后服务器发新的response给浏览器. 这时页面收到的request是一个新从浏览器发来的.

forward 发生在服务器内部, 在浏览器完全不知情的情况下发给了浏览器另外一个页面的response. 这时页面收到的request不是从浏览器直接发来了,可能己经放了数据.

所以:
request.setAttribute存的东西

只用通过方法2跳转 才能在新页取出来
用 DecimalFormat 格式化数字 引言 Java中对浮点数的输出表示 在Java中浮点数包括基本型float、double,以及对象包装类型的Float和Double,对于这些浮点数的输出,不管是显式地还是隐式地调用toString()得到它的表示字串,输出格式都是按照如下规则进行的 如果绝对值大于0.001、小于10000000,那么就以常规的小数形式表示。 如果在上述范围之外,则使用科学计数法表示。即类似于1.234E8的形式。 可以使用 java.text.DecimalFormat及其父类NumberFormat格式化数字 本例只浅述DecimalFormat的使用。 Pattern 0 - 如果对应位置上没有数字,则用零代替 # - 如果对应位置上没有数字,则保持原样(不用补);如果最前、后为0,则保持为空。 正负数模板用分号(;)分割 Number Format Pattern Syntax You can design your own format patterns for numbers by following the rules specified by the following BNF diagram: pattern := subpattern{;subpattern} subpattern := {prefix}integer{.fraction}{suffix} prefix := '\\u0000'..'\\uFFFD' - specialCharacters suffix := '\\u0000'..'\\uFFFD' - specialCharacters integer := '#'* '0'* '0' fraction := '0'* '#'* DEMO value 123456.789 pattern ,###.### output 123,456.789 Explanation The pound sign (#) denotes a digit, the comma(逗号) is a placeholder for the grouping separator, and the period(句号) is a placeholder for the decimal separator. 井号(#)表示一位数字,逗号是用于分组分隔符的占位符,点是小数点的占位符。 如果小数点的右面,值有三位,但是式样只有两位。format方法通过四舍五入处理。 value 123.78 pattern 000000.000 output 000123.780 Explanation The pattern specifies leading and trailing zeros, because the 0 character is used instead of the pound sign (#). 应用实例 1: /* * Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved. */ import java.util.*; import java.text.*; public class DecimalFormatDemo { static public void customFormat(String pattern, double value ) { DecimalFormat myFormatter = new DecimalFormat(pattern); String output = myFormatter.format(value); System.out.println(value + " " + pattern + " " + output); } static public void localizedFormat(String pattern, double value, Locale loc ) { NumberFormat nf = NumberFormat.getNumberInstance(loc); DecimalFormat df = (DecimalFormat)nf; df.applyPattern(pattern); String output = df.format(value); System.out.println(pattern + " " + output + " " + loc.toString()); } static public void main(String[] args) { customFormat("###,###.###", 123456.789); customFormat("###.##", 123456.789); customFormat("000000.000", 123.78); customFormat("$###,###.###", 12345.67); customFormat("\u00a5###,###.###", 12345.67); Locale currentLocale = new Locale("en", "US"); DecimalFormatSymbols unusualSymbols = new DecimalFormatSymbols(currentLocale); unusualSymbols.setDecimalSeparator('|'); unusualSymbols.setGroupingSeparator('^'); String strange = "#,##0.###"; DecimalFormat weirdFormatter = new DecimalFormat(strange, unusualSymbols); weirdFormatter.setGroupingSize(4); String bizarre = weirdFormatter.format(12345.678); System.out.println(bizarre); Locale[] locales = { new Locale("en", "US"), new Locale("de", "DE"), new Locale("fr", "FR") }; for (int i = 0; i posted on 2007-08-03 10:01 智者无疆 阅读(3813) 评论(8)  编辑  收藏 所属分类: about java
评论:
  • # re: java:redirect 和forward的区别,DecimalFormat及DecimalFormat的使用  智者无疆 Posted @ 2007-08-03 10:23
    about forward:在服务器端,用request.getPrameter得不到forward的URL中加入的参数.因为在浏览器的地址栏里根本不会显示URL,服务器要想用getPramater得到参数只能用redirect:这样,服务器先向浏览器返回一个response,顺带着也把URL显示到地址栏里了.然后再发送到服务器端.  回复  更多评论   

  • # re: java:redirect 和forward的区别,DecimalFormat及DecimalFormat的使用  myself Posted @ 2007-08-03 16:25
    //截取字符串中英文都转成字符型
    public String substring(String str, int toCount) {
    int reInt = 0;
    String reStr = "";
    if (str == null) return "";
    char[] tempChar = str.toCharArray();
    for (int kk = 0; (kk < tempChar.length && toCount > reInt); kk++) {
    String s1 = str.valueOf(tempChar[kk]);
    byte[] b = s1.getBytes();
    reInt += b.length;
    reStr += tempChar[kk];
    }

    return reStr;
    }  回复  更多评论   

  • # re: java:redirect 和forward的区别,DecimalFormat及DecimalFormat的使用  zhanglijun Posted @ 2007-08-15 19:59
    http://community.csdn.net/Expert/topic/5678/5678786.xml?temp=.434704  回复  更多评论   

  • # re: java:redirect 和forward的区别,DecimalFormat及DecimalFormat的使用[未登录]  lijun Posted @ 2007-08-17 16:14
    hibernate调用存储过程
    http://youlong05.javaeye.com/blog/24870
    xiansheng(刘宪生) 16:02:40
    http://tech.it168.com/j/2006-05-30/200605301146190.shtml
    http://www.fish888.com/Hibernate-t144218  回复  更多评论   

  • # re: java:redirect 和forward的区别,DecimalFormat及DecimalFormat的使用[未登录]  lijun Posted @ 2007-08-17 16:18
    http://blog.sina.com.cn/s/blog_415bd707010007zo.html
    CallableStatement cstmt = session.connection().prepareCall("{call pro_orderArticle(?, ?, ?, ?)}");
    cstmt.setInt(1, nodeId);
    cstmt.setString(2, oldOrderPath);
    cstmt.setString(3, orderPath);
    cstmt.setString(4, parentPath);
    try {
    cstmt.execute();
    } finally {
    cstmt.close();
    }  回复  更多评论   

  • # re: java:redirect 和forward的区别,DecimalFormat及DecimalFormat的使用[未登录]  lijun Posted @ 2007-08-17 18:44

    DROP PROCEDURE IF EXISTS vonibo_demo.test;

    CREATE PROCEDURE vonibo_demo.test
    BEGIN
    DECLARE userid int default 1;
    DECLARE stopFlag int default 0;
    DECLARE cursor_name CURSOR
    FOR select user_id from wb_product where product_id=1;
    DECLARE CONTINUE HANDLER FOR NOT FOUND set stopFlag=1;
    OPEN cursor_name;
    REPEAT

    FETCH cursor_name INTO userid;
    select * from wb_user where user_id=1;
    UNTIL stopFlag=1 END REPEAT;

    CLOSE cursor_name;
    END;
      回复  更多评论   

  • # lucene的使用及优化  zhanglijun Posted @ 2008-03-16 22:10
    http://zhan.cn.yahoo.com/articles/071128/47031_40.html  回复  更多评论   

  • # lucene的学习资源  zhanglijun Posted @ 2008-03-18 14:10
    Lucene学习资源
    1.基于Java的全文索引引擎Lucene简介
    http://www.chedong.com/tech/lucene.html
    2.Lucene中国
    http://www.lucene.com.cn/
    3.Lucene官方网站
    http://lucene.apache.org/
    4.Matrix论坛的Lucene版块
    Lucene与搜索引擎技术


      回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © 智者无疆 Powered by: 博客园 模板提供:沪江博客


   观音菩萨赞