Thinking in Patterns chapter 17: Multiple languages

Thinking in Patterns with Java V0.9: chapter 17: Multiple languages: TIPatterns.htm#_Toc41169757

1, Sections:

Multiple languages  120

  Interpreter motivation. 121

  Python overview.. 122

    Built-in containers. 123

    Functions. 124

    Strings. 125

    Classes. 127

  Creating a language. 130

  Controlling the interpreter. 134

    Putting data in. 134

    Getting data out. 140

    Multiple interpreters. 143

  Controlling Java from Jython  144

    Inner Classes. 148

  Using Java libraries. 148

    Inheriting from Java library classes  150

  Creating Java classes with Jython  151

    Building the Java classes from the Python code  156

  The Java-Python Extension (JPE)  157

  Summary. 157

  Exercises

2, The main content and feeling:

  First at all, let me remember a fact, this book is written at 3 years ago,

too many changes has been taken, so I think the language Python introduced

by Bruce in this book has many changes. And, there are many kinds of other languages maybe has present.

  Then, let us see what has been told in this chapter.

  At last, two days' reading without installing Python or Jython, I get a

conclusion: Python, maybe is the best lovely program language of Bruce's. The

most part of this chapter is introducing Python. On the other hand, the Interpreter Pattern in this Design patterns book is a little part of this chapter.

 

  What is Interpreter Pattern?

  It says:

 


  Sometimes the end users of your application (rather than the programmers of

that application) need complete flexibility in the way that they configure

some aspect of the program. That is, they need to do some kind of simple

programming. The interpreter pattern provides this flexibility by adding a

language interpreter.

 

  Note, although in almost all applications there are some factors that end

user can change it by some ways, for example, input something or press some

buttons, etc.. But, in a interpreter pattern, it provides end users the most probability for custom there many factors by simple programming.

  And, a ready for use this kind of Interpreter system introduced by Bruce is

Jython, a pure Java implementation of Python language. Of course, you can

write your own Interpreter sytem. But it seems too unecessary.

  Along with Bruce's lines, I got some about Python and Jython, and this is

almost real the first touch of this language for me. I can understand little

 bit of examples in this book without to run it under *ython.

  Use some sentences in this book to summary the understanding for *ython of

mine.

 


Python is a language that is very easy to learn, very logical to read

and write, supports functions and objects, has a large set of available

libraries, and runs on virtually every platform.

 

 


 It is marvelous for scripting, and you may find yourself

replacing all your batch files, shell scripts, and simple programs with Python

scripts. But it is far more than a scripting language.

 

 ...

 If you program with *ython, no redundant charactor typing. And it can be

worked together with java very well. All the Jython class and Java class can

almost interact without any problem. And, if you need native Python program

interact with Java, a resolution called The Java-Python Extension (JPE) can be

used.

  In this book, Bruce says maybe a new Design Pattern called Multiple Language

can be invented. In this way, mixing languages to resolve a question can be

better than using only one language. All the languages has its advantage and

shortage, mix them is a good idea.

  Bruce says:

 


  To me, Python and Java present a very potent combination for program

development because of Java?s architecture and tool set, and Python?s

extremely rapid development (generally considered to be 5-10 times faster than C++ or Java).

 

  But, I doubt that "5-10 times faster than C++ or Java", although I am not a

professional programmer(I don't work in IT), I think it is impossible that a

language has 5-10 times development speed than others. Because, building an

application need not only coding, but also many other works. I suppose, Python is good at coding, at building a good classes system, but, what classes are we need? How do they interact with each other? etc.. These kind of things is can't be reduced many only by a language.

 But, maybe, "Python?s extremely rapid development" is only refer to coding,

and mix this coding process with "Java's architecture" which is good at

building system architecture.

3, Questions about programming:

  1), if you create fields using the C++/Java style, they implicitly become static fields.

  2),

In addition, Jython’s JavaBean awareness means that a call to any method with a name that begins with “set” can be replaced with an assignment, as you can see above.

You are not required to inherit from Object; any other Java class will do.

Note that it?s important that the directory where the target lives be specified, so that the makefile will create the Java program with the minimum necessary amount of rebuilding.

4, Questions about english language:

1), Strange words:

 advantageous, arbitrarily, stuck, tedious, Interpreter, distraction, for-profit, royalties, basically, incorporating, scales up, purity, referred to, marvelous, affirmative, subsequent, add-on, acknowledged, associative, formalize, takes on, imitate, verbiage, signature, other than, tuple, control over, decimal place, spare, set off,  turns out to be,  aggressively, albeit, penchant, comma, from within, deceptively, thorough, further down, ambiguous, back and forth, it is worth noting that, disposal, endearing, intuitively, awareness, automated, shorthand, presumably,

come over, lambda, succinct, hood, frustrating, stem from, arguably, lurking,

potent, flesh out, terrific, leverage

2), Strange sentences:

 Indenting can nest to any level, just like curly braces in C++ or Java, but unlike those languages there is no option (and no argument) about where the braces are placed  the compiler forces everyone’s code to be formatted the same way, which is one of the main reasons for Python’s consistent readability.

 Note that Python was not named after the snake, but rather the Monty Python comedy troupe, and so examples are virtually required to include Python-esque references.

   incomplete

Thinking in Patterns Chapter 16: Complex interactions

Thinking in Patterns with Java V0.9: Chapter 16: Complex interactions: TIPatterns.htm#_Toc41169753

 1, Sections:

Externalizing object state  113

  Memento. 113

Complex interactions  114

  Multiple dispatching. 114

  Visitor, a type of multiple dispatching  117

  Exercises

2, The main content and feeling:

  Memento Pattern isn't described in this book(So I don't write a diary of Chapter 16: Externalizing object state), I must learn it in other place.

 

  After twice reading of chapter: Complex interactions, I got little from the book. Don't like Thinking in Java, in that book, there is detail explaination after every example. But, it isn't given explaination in this chapter's two examples. This book is only Version0.9.

  1), What is Multiple dispatching? I knew it from this point: "Remember that polymorphism can occur only via member function calls, if you want double dispatching to occur, there must be two member function calls: the first to determine the first unknown type, and the second to determine the second unknown type." 

  Just describe it use the example in the book below:


class Scissors implements Item {

  public Outcome compete(Item it) { return it.eval(this); }

  public Outcome eval(Paper p) { return Outcome.LOSE; }

  // ...

}


class Paper implements Item {

  public Outcome compete(Item it) { return it.eval(this); }

  public Outcome eval(Paper p) { return Outcome.DRAW; }

  //..

}

  Here, a scissors vs. a paper:

  s Item = new Scissors();

  p Item = new Paper();

  s.compete(p); // the first(method compete()) to determine the first unknown type(Scissors),

 

  //In the method "compete()", the second method is called

  p.eval(s);// the second(method eval()) to determine the second unknown type(Paper),

  Why does the first(method compete()) NOT to determine the second unknown type(Paper)?

  The key is this statement above:

  polymorphism can occur only via member function calls

  When the method compete() be called, the type of the object that call this method is determined, "Item" "s" is a "Scissors".

  The second method eval() is same as the first method complete().

  2), Visitor, a type of multiple dispatching

 

  After know the Mutiple dispatching, Vistor Pattern is understood soon. Because, it "builds on the double dispatching scheme shown in the last section".

  There is a point need to note, the purpose of using Vistor Patterns is changing the method's behavior without modifying original hierarchy.

  I explain this using the example in the book too:

  In this example, Flower classes hierarchy can't be changed. And can determining it's type by calling it's method: accept(Visitor v);

 

  Although Flower classes herarchy can't be changed, but Visitor classes herarchy can be changed, so there are two types of Visitor be created, one is "StringVal", another is "Bee". And, the second Type be determined in this method below:

  v.visit(this); //"this" is a Flower, when the "v" call visit() method, its type be termined. And, different type Vistor visit(this) can get different behavior, that just we want to get.

  3), Multiple dispatching can be replaced by a table lookup, just look it in the exercise 3.

  I think there are two type of Map will be used. it is one: key is class, value is another map; another map: key is class, value is outcome.

  4), At this point, I suddenly think, I guess, Bruce thinks the Design Pattern isn't a very import thing in his software design, I feel his words outside this book is just saying: many of these "Dsign Patterns" is redundant, a basic idea of mine be divided into these too many Patterns, this basic idea is: No pattern is patterns for all.

  This is only my guess, my feeling. If my feeling is right, maybe, we maybe can't see a version1.0 of this book:(

  My english language and program knowledge is poor, if I make any mistake, please tell me: mdx-xx@tom.com

 

3, Questions about programming:

  1), The answer starts with something you probably don’t think about: Java performs only single dispatching. That is, if you are performing an operation on more than one object whose type is unknown, Java can invoke the dynamic binding mechanism on only one of those types. This doesn’t solve the problem, so you end up detecting some types manually and effectively producing your own dynamic binding behavior.

  2), How to do if there are more than double dispatching in the above?

  Like below?

  a.F(b);

  b.G(c);

  c.H(a);

  ...

  3), All the exercises.

 

4, Questions about english language:

1), Strange words:

 compete, Scissors, Outcome, primary, dilemma, virtualize, bound, Gladiolus, Runuculus, Chrysanthemum, Inhabitant, Dwarf, Elf, Troll, Jargon, InventFeature,

Each Inhabitant can randomly produce a Weapon using getWeapon( ): a Dwarf uses Jargon or Play, an Elf uses InventFeature or SellImaginaryProduct, and a Troll uses Edict and Schedule.

syntactic, simplicity,

2), Difficult sentences:

The easiest way to do this is to create a Map of Maps, with the key of each Map the class of each object.

 

******************************************************************

The class diagrams of two examples in the book:

1),//: multipledispatch:PaperScissorsRock.java

2),//: visitor:BeeAndFlowers.java



 

    incomplete

Googlebot和 Mediapartners-Google 抓取报告中的怪事

Googlebot是google搜索抓取机器人,而Mediapartners-Google是为显示相关广告而抓取网页的机器人。

这几天,在Googlebot的抓取报告中出现这样的莫名其妙的字眼:


我们已成功访问您的主页。

-----------------------------------------------------------

restriction. not be translated.

而在Mediapartners-Google的抓取报告中出现莫名其妙的robots.txt拦截网址,问题是我在robots.txt中根本就没有拦截这些网址:


        已拦截网址      拦截原因  [?]    上一次抓取尝试     尝试失败

  http:/ / 209. 85. 165. 104/ search? q= cache:hIzBannSd6wJ:java. learndiary. com/ diaries/ 1367. jsp+error+1045+access+denied+for+user+root%40localhost&hl= zh-CN&gl= us&ct= clnk&cd= 7 Robots.txt 文件 2006-12-29 1

  http:/ / 64. 233. 161. 104/ search? q= cache:tvsE7YLr87kJ:java. learndiary. com/ diaries/ 1481. jsp+hibernate+spring&hl= zh-CN&gl= us&ct= clnk&cd= 128 Robots.txt 文件 2006-12-27 1

截图分别如下:

1)、Googlebot的抓取报告

2)、Mediapartners-Google的抓取报告

Thinking in Patterns Chapter 14: Algorithmic partitioning

Thinking in Patterns with Java V0.9: Chapter 14: Algorithmic partitioning: TIPatterns.htm#_Toc41169746

1, Sections:

Algorithmic partitioning  106

  Command: choosing the operation at run-time  106

    Exercises. 109

  Chain of responsibility. 109

    Exercises

2, The main content and feeling:

  1) Command pattern:

  It is "wrapping a method in an object". From my understanding, a Command is a very simple class with a sole method to resolve a specific task. When I perform a big task, I can put some of these Command objects together, and in a "manager" class, call these object's own sole method to perform its specific little task, and, in this way, to finish that big task through these little object's contributions.

 

  In my first touch of these patterns, I think there are clear differents between Command Pattern and Strategy Pattern:

  Command Pattern: Put serveral Command objects together to perform a common task, just like draw together to fight on a common enemy;

  Strategy Pattern: At a specific time use a specific Strategy to accomplish a different result.

  But, why does Bruce say below in the book:

 


 I would hazard to say that Command provides flexibility while you’re writing the program, whereas Strategy’s flexibility is at run time. Nonetheless, it seems a rather fragile distinction.

 

 

  Maybe, Bruce describe it from the structural aspect, I look at them at the function's aspect.

  

  2) Chain of Responsibility:

  That just an "Expert System", there are several experts in this system, and, these experts wait here in line. When a problem come, from the first expert to the last expert, every expert try to resolve this problem. If one can't do it, then the problem be handed to the next expert, until the problem be rosolved or the last expert can't do it yet, then an un-resolved problem is retruned.

  From this view aspect, Chain of Responsibility just like an auto-selected Strategy Pattern: the method for resolving problem is auto selected in the former, and a manual-selected strategy used for a problem in the later.

  A question raises, what if the problem handed to the Expert System need serveral experts to resolve them respectively? Maybe, this problem need to be cuted into serveral little problems then hand them into the expert system successively.

  In this pattern, Bruce says GoF use many words to create an linked list to contain these "experts", it is because GoF wrote that Design Pattern at the time "before the Standard Template Library (STL) was incorporated into most C++ compilers'. But, in Java, a ready-made List is here.

  In fact, I need review these content when I finish the first reading of this book. So, although there are some place I can't understand it very clearly, but, I must go on, finish the first reading of entire book in shortest time is the most import thing. I just only read half of this book. After reading this book once, the J2EE Design Patterns need me to read. So, don't tie at any specific point, go! go! go!

3, Questions about programming:

  1), The point is to decouple the choice of function to be called from the site where that function is called.

  2),  something you can normally only do by writing new code but in the above example could be done by interpreting a script.

  3), What is the famous "callback" technique?

4, Questions about english language:

1), Strange words:

   functor, collectively, incorporated into, BabelFish, Bisection, ConjugateGradient, fragile

2), Difficult sentences:

On the other hand, with a Command object you typically just create it and hand it to some method or object, and are not otherwise connected over time to the Command object.

 

********************************************************************************************************

Class diagram of //: chainofresponsibility:FindMinima.java in section: Chain of responsibility

                                     incomplete

让孩子唱孩子应该唱的,玩孩子应该玩的吧

今天,有两个事情使我要写这篇日记。

1、某处元旦节庆祝。其中有两个小学二三年级的孩子唱歌和跳舞,唱的是S.H.E的《不想长大》,歌词是这样的:


...

我不想我不想不想长大

长大后世界就没有花

我不想我不想不想长大

我宁愿永远又笨又傻

我不想我不想不想长大

长大后我就会失去他

我深爱的他深爱我的他

已经变的不像他

...

完整的见:

http://mp3.baidu.com/m?tn=baidump3lyric&word=%B2%BB%CF%EB%B3%A4%B4%F3&ct=150994944&lm=-1&lf=3

其中一个还跳着很成人的舞姿。

相反,有个成人上台表演跳的是很传统的蒙古草原舞蹈。

2、女儿让我给她买一种贴纸画,我不知道是哪种(后来知道是泡泡糖里的),就看了另外的贴纸画,清一色的是武侠小说里的人物:好像有:小龙女,小李飞刀什么的。听店主说,这种贴纸卖得很好。这个小店就紧挨着一个幼儿园。

而且,我想起现在许多小孩都在唱不是他们该唱的歌,看不是他们该看的漫画(尤其是有些日本的卡通漫画),这让我很想说:让孩子唱孩子应该唱的,玩孩子应该玩的吧。

在我的心里,孩子的世界应该是童话的、纯洁的世界。里面有灿烂的阳光、蓝蓝的天、绿绿的草、五颜六色的花,还有蝴蝶等。。。

但是,现实是严竣的,以上两个小事只是冰山一角。

难道,我们找不到给孩子唱的,给孩子玩的吗?我不这样认为。而且,我也不认为,孩子们就只有看外国动画、漫画(这段时间我们的孩子嘴里常念叨的是什么:奥特曼、迪克、超人、怪兽;葫芦娃也有提,时候不多;我想,我们从来没有给她看这些,一定是她的小朋友圈子中互相交流的热门主题,哪个最英雄,我要当奥特曼、超人,打怪兽...)。我们的血液里天生有一份最值钱的祖宗留下的、世界仅有的宝贵财富:5000年厚重的文化传承,这一点也可以说,中国人是世界最富有的人,我们应该为生为中国人而骄傲。

难道,这悠悠5000年的文化还找不到怎样来滋润孩子心灵的灵感和源泉吗?不会吧。我们完全可以以现代的科技,随便在5000年的历史长河中捡一点,就能做出至少是中国的唐老鸭和米老鼠,进一步,做成世界级的东西也不是没有可能。我们的东西有不少是外国人在发挥,像日本的三国文化(包括:游戏、漫画等),美国的花木兰,当然,应该还有太多,不过我没有去找,如果是专心去找,肯定有不少的。

作为一个家长、孩子的父亲,我希望我们的孩子能够唱他们该唱的、玩他们该玩的、看他们该看的。

linux下的换行符号引起Resin3的struts-config.xml解析报错

由于linux和windows的换行符不一致,有时在这种系统间的文件交换就会出现问题。我就碰到这样的问题。

本来应该是这样的Struts-config.xml内容:


        <action

            attribute="loginForm"

            input="/login.jsp"

            name="loginForm"

            path="/loginAction"

            type="com.learndiary.website.action.account.LoginAction">

            <forward name="success" path="/loginSuccess.jsp" />

            <forward name="failure" path="/login.jsp" />

        </action>

可能是从windows转到linux下变成了这样:


        <action^M^M

            attribute="loginForm"^M^M

            input="/login.jsp"^M^M

            name="loginForm"^M^M

            path="/loginAction"^M^M

            type="com.learndiary.website.action.account.LoginAction">^M^M

            <forward name="success" path="/loginSuccess.jsp" />^M^M

            <forward name="failure" path="/login.jsp" />^M^M

        </action>

这在本地的Tomcat5和空间原来的Resin2下都没有问题,但是当空间改为Resin3后,每次重新启动应用就报错:


The content of element type "action" must match "(icon?,display-name?,description?,set-property*,exception*,forward*)".

...

但是奇怪的是,应用启动后的工作看起来还是正常的。

下面附的是相关的文字:(转自:http://www.real-blog.com/linux-bsd-notes/67

Unix 及 Windows 文字檔轉換

大家如果試過在 Linux 及 Windows 文字檔分享的話,會發現文字檔的 “換行” 不一樣。在 Windows 用記事本開啟 Unix 文字檔時,文件不會開新行,需要使用支援 Unix 格式的文字編輯器才可看到分行;而在 Linux 開啟 Windows 的文字檔時,在每一行最後會有字元 Ctrl-m (^M)。以下是使用 Perl 在 Linux 下將文字檔轉換的方法:

Windows 格式 -> Unix 格式

perl -p -e ’s/\r$//’ < winfile.txt > unixfile.txt

Unix 格式 -> Windows 格式

perl -p -e ’s/\n/\r\n/’ < unixfile.txt > winfile.txt

February 13, 2006 · Linux / BSD 筆記, Windows 筆記 ·

1 Comment »

   1.

      UNIX WINDOWS MAC三者的回车都不一样,好像是:windows是0×0d 0×0a

      UNIX是0×0d MAC是0×0a吧。记不太清楚了。大体上是这样的。

      Comment by 数据恢复 — April 6, 2006 @

始终没有搞懂Java中的字符编码问题

在本站动态页面静态化中,使用的是用程序访问网页,然后把返回的内容写入静态文件。由于本站是采用UTF-8编码,所以,保存的静态文件就要以UTF-8格式保存。

在我本机的环境下(redhat linux9.0 + jdk1.4.2 + tomcat5 )和现在的空间环境windows2000 advanced + jdk1.5 + Resin3.0.18下,使用下面的代码可以正确保存为UTF-8静态文件:


/*

 * Created on 2006-12-1

 */

package com.learndiary.website.util;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import com.learndiary.website.model.UserInfo;

public class ToHtml extends HttpServlet {

private static Log __log = LogFactory.getFactory().getInstance("com.learndiary.website.util.ToHtml");

public void service(

HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

String url = "";

String name = "";

ServletContext sc = getServletContext();

String fileName = request.getParameter("fileName");

String artID = request.getParameter("artID");

String pageNum = request.getParameter("pageNum");

String webPath = null;

        if (fileName.equals("main")){

url = "/main.do";

webPath = "/index.htm";

__log.info("main url is: " + url +" ; static html file name is: " + webPath);

}else if(fileName.equals("goal")){

url = "/disGoalContentAction.do?goalID=" + artID; // 你要生成的页面的文件名。

webPath = "/goals/" + artID + ".htm";

__log.info("goal url is: " + url +" ; static html file name is: " + webPath);

}else if(fileName.equals("diary")){

    url = "/disDiaryContentAction.do?goalID=" + artID; // 你要生成的页面的文件名。

    webPath = "/diaries/" + artID + ".htm";

    __log.info("diary url is: " + url +" ; static html file name is: " + webPath);

    }else if(fileName.equals("sitemap")){

    url = "/mapGenerateAction.do?artID=" + artID + "&pageNum=" + pageNum ; // 你要生成的页面的文件名。

    int articleID = Integer.parseInt(artID);

    if (articleID == 0){

        webPath = "/sitemaps/goals-" + pageNum + ".htm";

    }else if (articleID > 0){

        webPath = "/sitemaps/goal" + artID + "-" + pageNum + ".htm";

    }

    __log.info("sitemap url is: " + url +" ; static html file name is: " + webPath);

    }

        name = request.getRealPath(webPath);

       

        __log.info("real name is: " + name);

       

RequestDispatcher rd = sc.getRequestDispatcher(url);

final ByteArrayOutputStream os = new ByteArrayOutputStream();

final ServletOutputStream stream = new ServletOutputStream() {

public void write(byte[] data, int offset, int length) {

os.write(data, offset, length);

}

public void write(int b) throws IOException {

os.write(b);

}

};

final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os));

HttpServletResponse rep = new HttpServletResponseWrapper(response) {

public ServletOutputStream getOutputStream() {

return stream;

}

public PrintWriter getWriter() {

return pw;

}

};

rep.setContentType("text/html; charset=UTF-8");

rd.include(request, rep);

pw.flush();

FileOutputStream fos = new FileOutputStream(name);



byte[] ob= os.toByteArray();

//String string =new String(ob, "GB2312");//在本站如果输入繁体字等这样不能显示繁体字(应该是只能正确处理GB2312的内容)

String string =new String(ob);//这样才能正确处理繁体字

byte[] ob2 = string.getBytes("UTF-8");

fos.write(ob2);

        //os.writeTo(fos);

fos.close();

String jspName = webPath.replaceAll(".htm", ".jsp");

if (!HtmlsManager.isExist(jspName, request)){ //write another same name's jsp static file that will include html file

FileOutputStream jspFos = new FileOutputStream(name.replaceAll(".htm", ".jsp"));

String content = "<%@ include file=\"/common/jsp301.jsp\" %>".concat("<jsp:include page=\"" + webPath + "\" />");

byte[] jspOb = content.getBytes("UTF-8");

jspFos.write(jspOb);

jspFos.close();

__log.info("wrote static file name in ToHtml.java is: " + jspName + ", and content is: " + content);

}

__log.info("wrote static file name in ToHtml.java is: " + name);



}

}

而在原来的空间环境下:windows2000 advanced + jdk1.5 + Resin2下,上面红色的部分必须为下面的代码才行,否则是乱码:


FileOutputStream fos = new FileOutputStream(name);

        os.writeTo(fos);

fos.close();

String jspName = webPath.replaceAll(".htm", ".jsp");

if (!HtmlsManager.isExist(jspName, request)){ //write another same name's jsp static file that will include html file

FileOutputStream jspFos = new FileOutputStream(name.replaceAll(".htm", ".jsp"));

String content = "<%@ include file=\"/common/jsp301.jsp\" %>".concat("<jsp:include page=\"" + webPath + "\" />");

byte[] jspOb = content.getBytes();

jspFos.write(jspOb);

jspFos.close();

__log.info("wrote static file name in ToHtml.java is: " + jspName + ", and content is: " + content);

}

__log.info("wrote static file name in ToHtml.java is: " + name);

由于我对上面文件操作和字符编码的掌握也是模棱两可的,也不知道为什么要这样做,只知道这样做的结果是正确的。所以,就算是结果正确,上面的代码也很有可能有问题。像这些基础的技术确实应该真正理解和掌握。

这里有一个JAVA字符编码讲得比较透彻的文章,以后可以照着学一下。

    上篇:http://www.pconline.com.cn/pcedu/empolder/gj/java/0404/366404.html

    下篇:http://www.pconline.com.cn/pcedu/empolder/gj/java/0405/368760.html

Resin-3.0.18中出现的 "c:if" must not contain the '<' characte

本站移入Resin3.0.18后出现了一些问题,其中就是当调用一个jsp文件:/disall2.jsp时,出现下列报错,而这在原来的Resin2.*和Tomcat5.0.*是没有出现过的。


500 Servlet Exception

/disall2.jsp:1: org.xml.sax.SAXParseException: The value of attribute "test"

associated with an element type "c:if" must not contain the '<' character.

Resin-3.0.18 (built Fri, 24 Feb 2006 02:47:03 PST)

经过一行一行的检查文件中的<c:if>标记(JSTL的标记),发现下面一段可疑的代码:


     <c:if test="false">

      <font size="3">

     </c:if>

     <c:if test="false">

      <font size="4">

     </c:if>

里面有小于号“<”,于是试着把上面的代码改成:


     <c:if test="false">

      <font size="3">

     </c:if>

     <c:if test="false">

      <font size="4">

     </c:if>

这样,就OK了。

在JSTL的关系运算中,有两套等效的运算符。如:ge 相当于 >= ;lt 相当于 < ;le 相当于 <= 等等。

完整的有:


类别  运算符

算术运算符 + 、 - 、 * 、 / (或 div )和 % (或 mod )

关系运算符 == (或 eq )、 != (或 ne )、 < (或 lt )、 > (或 gt )、 <= (或 le )和 >= (或 ge )

逻辑运算符 && (或 and )、 || (或 or )和 ! (或 not )

验证运算符 empty

但是它们的使用有什么区别呢?我还不知道。谁知道了提一下,谢谢。

网页上几段script代码引起的网页正文加载问题

我发现诸如:

<script src="http://dict.cn/hc/" type="text/javascript"></script>

这类的script加载代码如果执行不能完成有可能引起整个网页的加载不能完成。

我发觉这类代码的执行是顺序进行的。也就是说,如果某段这类的代码没有执行完成的话,它后面的内容也不会执行。所以,如果后面有网页正文的内容的话,整个网页正文都显不出来。如果把这类代码放在了一个表格中,由于表格必须里面所有的内容加载完后才能显示出来,当这类代码的执行不能完成,所有表格的内容都显示不出来。

今天中午,我发现由于Dict.CN的划词代码(我放在网页的最前面的)执行不能完成,导致整个网页内容不能显示出来;还有,奇怪的是,今天cnzz的统计代码也不能执行完成,导致其后面的内容不能执行(如我统计帖子访问的计数代码,不是cnzz的统计计数,是我自己的用数据库保存的帖子访问计数。)

现在,我按:自己的页面统计计数代码,Dict.CN划词翻译代码,cnzz统计代码的顺序把这些代码放在了紧接</body>的前面,也是全部网页的最后。这样,这些代码就不会影响整个网页正文的加载了。

划词翻译的开关状况代码仍然是放在网页的最前面的,我想,这个开关状态代码没有调用Dict.CN网站上的资源,不会引起加载延迟吧。

附上面提到的几段script代码:

1、划词翻译状态开关代码,放在网页的最前面:


<span id="dict_status"></span>

下面的代码按序放在紧接</body>之前(这个位置科不科学还未考证):

2、本站自己的帖子页面计数代码:


<script language="javascript" src="/count.do?artID=<c:out value="${aGoal.articleID}"/>"></script>

3、Dict.CN的划词翻译代码:


<script src="http://dict.cn/hc/" type="text/javascript"></script>

<script type="text/javascript">

dictInit();

</script>

4、cnzz的页面访问统计代码:


<script src='http://s**.cnzz.com/stat.php?id=***&web_id=***&show=pic' language='JavaScript' charset='gb2312'></script>

看来,script在网页上用处真的很大,什么时候也该好好学一下了。

怎样控制iframe内嵌网页的位置

在日记静态页面嵌入jsp动态页面的一些总结和疑问中有一个问题如下:


1、页面菜单上部的用户信息是用iframe嵌入的,像下面:

   <!-- show user state with iframe framework -->

   <iframe frameborder="0" name="user_state" width="771" height="30"

scrolling="no" src="/common/userState.jsp"></iframe>

/common/userState.jsp是从当前session中取出用户的相关信息显示出来。

不过,我发现: 在firefox中位置不动的信息条在IE中却可以用鼠标上下移动,而且,始

位置在底部,还把字脚给挡住了,搞不懂怎么做了?

昨天,在把Dict.CN的部分免费学英语服务加在网站上的过程中,借鉴了iciba.com的多爱英文中的查词代码,把上面的代码改成下面这个样子,这样,在IE和firefox中这个iframe中的内容都能靠上正常显示了。如下:


<DIV><IFRAME border="0" marginWidth="0" marginHeight="0" src="/common/userState.jsp" frameBorder="no" width="771" scrolling="no" height="21"></IFRAME></DIV>

我不知道究竟是DIV的原因还是marginWidth或者marginHeight的原因,反正结果正常了。又是一个知其然不知其所以然的问题:)。

以后对这类技术还是应该进行系统的学习才是解决这些问题的根本。