Pages

Friday, November 25, 2011

Google Swiffy extension exports Flash to HTML5, ActionScript fans rejoice


Google Swiffy extension exports Flash to HTML5, ActionScript fans rejoice
Published on Engadget | shared via feedly mobile
If you were bummed that you'd have to pick up some new coding skills when Adobe announced that Flash for mobile was finito, cheer up friends. Harken back to the summer months when Google unveiled its Swiffy conversion tool that turns those aging SWF files into browser friendly HTML5 animations. Now the folks in Mountain View have created an extension for the Flash desktop app that allows you to export your working files to something a little more up to date with a single click -- or a combination of keystrokes for you pros. So if you're worried you'd have to brush up on your coding wizardry, it seems you're safe... for now. If you're sporting Flash CS4 or newer, hit that source link to download the goods.

Google Swiffy extension exports Flash to HTML5, ActionScript fans rejoice originally appeared on Engadget on Fri, 18 Nov 2011 21:08:00 EDT. Please see our terms for use of feeds.

Permalink InfoWorldsourceGoogleEmail this | Comments



Sent from my iPhone

Thursday, November 24, 2011

App server VS. Web server

What is the difference between an application server and a Web server?
ATaking a big step back, a Web server serves pages for viewing in a Web browser, while an application server provides methods that client applications can call. A little more precisely, you can say that:
A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.


Let's examine each in more detail.

The Web server

A Web server handles the HTTP protocol. When the Web server receives an HTTP request, it responds with an HTTP response, such as sending back an HTML page. To process a request, a Web server may respond with a static HTML page or image, send a redirect, or delegate the dynamic response generation to some other program such as CGI scripts, JSPs (JavaServer Pages), servlets, ASPs (Active Server Pages), server-side JavaScripts, or some other server-side technology. Whatever their purpose, such server-side programs generate a response, most often in HTML, for viewing in a Web browser.
Understand that a Web server's delegation model is fairly simple. When a request comes into the Web server, the Web server simply passes the request to the program best able to handle it. The Web server doesn't provide any functionality beyond simply providing an environment in which the server-side program can execute and pass back the generated responses. The server-side program usually provides for itself such functions as transaction processing, database connectivity, and messaging.
While a Web server may not itself support transactions or database connection pooling, it may employ various strategies for fault tolerance and scalability such as load balancing, caching, and clustering—features oftentimes erroneously assigned as features reserved only for application servers.

The application server

As for the application server, according to our definition, an application server exposes business logic to client applications through various protocols, possibly including HTTP. While a Web server mainly deals with sending HTML for display in a Web browser, an application server provides access to business logic for use by client application programs. The application program can use this logic just as it would call a method on an object (or a function in the procedural world).
Such application server clients can include GUIs (graphical user interface) running on a PC, a Web server, or even other application servers. The information traveling back and forth between an application server and its client is not restricted to simple display markup. Instead, the information is program logic. Since the logic takes the form of data and method calls and not static HTML, the client can employ the exposed business logic however it wants.
In most cases, the server exposes this business logic through a component API, such as the EJB (Enterprise JavaBean) component model found on J2EE (Java 2 Platform, Enterprise Edition) application servers. Moreover, the application server manages its own resources. Such gate-keeping duties include security, transaction processing, resource pooling, and messaging. Like a Web server, an application server may also employ various scalability and fault-tolerance techniques.

An example

As an example, consider an online store that provides real-time pricing and availability information. Most likely, the site will provide a form with which you can choose a product. When you submit your query, the site performs a lookup and returns the results embedded within an HTML page. The site may implement this functionality in numerous ways. I'll show you one scenario that doesn't use an application server and another that does. Seeing how these scenarios differ will help you to see the application server's function.

Scenario 1: Web server without an application server

In the first scenario, a Web server alone provides the online store's functionality. The Web server takes your request, then passes it to a server-side program able to handle the request. The server-side program looks up the pricing information from a database or a flat file. Once retrieved, the server-side program uses the information to formulate the HTML response, then the Web server sends it back to your Web browser.
To summarize, a Web server simply processes HTTP requests by responding with HTML pages.

Scenario 2: Web server with an application server

Scenario 2 resembles Scenario 1 in that the Web server still delegates the response generation to a script. However, you can now put the business logic for the pricing lookup onto an application server. With that change, instead of the script knowing how to look up the data and formulate a response, the script can simply call the application server's lookup service. The script can then use the service's result when the script generates its HTML response.
In this scenario, the application server serves the business logic for looking up a product's pricing information. That functionality doesn't say anything about display or how the client must use the information. Instead, the client and application server send data back and forth. When a client calls the application server's lookup service, the service simply looks up the information and returns it to the client.
By separating the pricing logic from the HTML response-generating code, the pricing logic becomes far more reusable between applications. A second client, such as a cash register, could also call the same service as a clerk checks out a customer. In contrast, in Scenario 1 the pricing lookup service is not reusable because the information is embedded within the HTML page. To summarize, in Scenario 2's model, the Web server handles HTTP requests by replying with an HTML page while the application server serves application logic by processing pricing and availability requests.

Caveats

Recently, XML Web services have blurred the line between application servers and Web servers. By passing an XML payload to a Web server, the Web server can now process the data and respond much as application servers have in the past.
Additionally, most application servers also contain a Web server, meaning you can consider a Web server a subset of an application server. While application servers contain Web server functionality, developers rarely deploy application servers in that capacity. Instead, when needed, they often deploy standalone Web servers in tandem with application servers. Such a separation of functionality aids performance (simple Web requests won't impact application server performance), deployment configuration (dedicated Web servers, clustering, and so on), and allows for best-of-breed product selection.

About the author

Tony Sintes is an independent consultant and founder of First Class Consulting, a consulting firm that specializes in bridging disparate enterprise systems and training. Outside of First Class Consulting, Tony is an active freelance writer, as well as author of Sams Teach Yourself Object-Oriented Programming in 21 Days (Sams, 2001; ISBN: 0672321092).
Read more about Tools & Methods in JavaWorld's Tools & Methods section.

from: http://www.javaworld.com/javaworld/javaqa/2002-08/01-qa-0823-appvswebserver.html?page=2



Wednesday, November 23, 2011

XSL

from: http://www.w3schools.com/xsl/xsl_languages.asp
It started with XSL and ended up with XSLT, XPath, and XSL-FO.

It Started with XSL

XSL stands for EXtensible Stylesheet Language.
The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML-based Stylesheet Language.

CSS = Style Sheets for HTML

HTML uses predefined tags, and the meaning of each tag is well understood.
The <table> tag in HTML defines a table - and a browser knows how to display it.
Adding styles to HTML elements are simple. Telling a browser to display an element in a special font or color, is easy with CSS.

XSL = Style Sheets for XML

XML does not use predefined tags (we can use any tag-names we like), and therefore the meaning of each tag is not well understood.
A <table> tag could mean an HTML table, a piece of furniture, or something else - and a browser does not know how to display it.
XSL describes how the XML document should be displayed!

XSL - More Than a Style Sheet Language

XSL consists of three parts:
  • XSLT - a language for transforming XML documents
  • XPath - a language for navigating in XML documents
  • XSL-FO - a language for formatting XML documents

Display Blob(Image) from Mysql table using JSP


In this section, we will display blob data(image) from Mysql database table using JSP code.
A Blob stores a binary large object in the database table's row. Blob object contains a logical pointer which points to the Blob data, data is not directly stored in the row of the database table. Blob object  is valid for the duration of the transaction. The "getBlob()" and  "setBlob()" method of "ResultSet" ,"CallableStatement", and "PreparedStatement" interface , is used for accessing Blob value.
The Method defined in " java.sql.Blob " interface is as follows--
Return Type    Method                                         Description 

InputStream        getBinaryStream()                       Retrieves the blob value designated
                                                                                 by this blob value as a stream

byte[]                 getBytes(long pos, int length)         Retrieve all or part of the blob value that
                                                                                 this blob represents as an array of bytes.

long                    length()                                          Returns the no of bytes in the Blob
                                                                                 value designated by this Blob object

OutputStream     setBinaryStream(long pos)           Retrieves a stream that can be used
                                                                                 to write to the Blob value 

int                       setBytes(long pos, byte[] bytes)    Write the given array of bytes to the Blob
                                                                                 value that this Blob object represent
                                                                                 starting at  position pos, and returns the no
                                                                                 of bytes written 

void                    truncate(long len)                            Truncates the blob value that this blob
                                                                                  object represents to be len bytes in len

Blob data type can further be classified into four types--
  • TINYBLOB: The maximum length is 255 characters (8 bits)
  • BLOB: The maximum length is 16,535 characters (16 bits)
  • MEDIUMBLOB: The maximum length is 16,777,216 characters (24 bits)
  • LONGBLOB: The maximum length is 4,294,967,295 characters (32 bits).
EXAMPLE :
displayblob.jsp
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<% Blob image = null;
Connection con = null;
byte[ ] imgData = null ;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://192.168.10.13:3306/ankdb","root","root");
stmt = con.createStatement();
rs = stmt.executeQuery("select image from inimage where id = '6'");
if (rs.next()) {
image = rs.getBlob(1);
imgData = image.getBytes(1,(int)image.length());
else {
out.println("Display Blob Example");
out.println("image not found for given id>");
return;
}
// display the image
response.setContentType("image/gif");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
catch (Exception e) {
out.println("Unable To Display image");
out.println("Image Display Error=" + e.getMessage());
return;
finally {
try {
rs.close();
stmt.close();
con.close();
catch (SQLException e) {
e.printStackTrace();
}
}
%>
OUTPUT :
Related Tags for Display Blob(Image) from Mysql table using JSP :

from: http://www.roseindia.net/tutorial/java/jsp/jspdisplayblob.html

Tuesday, November 22, 2011

Using a RequestDispatcher

Chapter 18: Using a RequestDispatcher

The request dispatcher is an important tool for any J2EE developer who is building a web application that involves multiple JSPs and Servlets. In this chapter, we are going to look at it in detail.

So, lets get started!!!

The RequestDispatcher

The RequestDispatcher is a useful tool. You can perform programmatic server-side includes or route the whole request to another servlet or JSP with a forward. The purpose of the request dispatcher is to direct control from one jsp/servlet to another so that the application can take a course of action that would help complete the current user request.

Getting the Request Dispatcher

The request dispatcher can be obtained in 3 ways. They are:
1. ServletContext.getRequestDispatcher(java.lang.String)
2. ServletContext.getNamedDispatcher(java.lang.String)
3. ServletRequest.getRequestDispatcher(java.lang.String)

The first two ways are getting the dispatcher from the servlet context. Either way of invoking returns a RequestDispatcher object that acts as a wrapper for the named servlet.

Whereas, the third way uses the servlet request. You can use a relative pathname here whereas with the servletcontext we need to use the absolute pathname.

Exam Trivia:
We need to be careful while using the paths. If the path begins with a “/”, it is interpreted as relative to the current context root. You will get a null if the servlet container cannot return a RequestDispatcher. Be sure to use the correct path name and to spot inconsistencies in the code in case the exam puts one in front of you.

Purpose of the RequestDispatcher: 

The RequestDispatcher object can be used to forward a request to the resource or to include output from the resource in a response. The specification allows the resource to be dynamic or static. If it is dynamic, such as a servlet, the container will invoke that servlet, and then take the output and include it. If it is static, such as a text file, then the container will include the text as it is.

Lets now look at some sample code as to how the RequestDispatcher can be used.

Sample Code 1: 

public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
try {
getServletConfig()
.getServletContext()
.getRequestDispatcher("/SomeExample")
.forward(request, response);
} catch (Exception ex) {
ex.printStackTrace ();
}
}

The above code can be used to forward the control to the SomeExample servlet and include the contents of its output as part of this requests response back to the browser.

Sample Code 2: 

RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher(path);
if (dispatcher == null)
{
out.println(path + " not available");
return;
} else
{
dispatcher.include(request, response);
}

You can also include contents from a static page or another servlet in your response. The above code is how you can do it.

Did you notice the difference in the above 2 examples?

If you did not, just scroll up and see the code again. In example 1 I had used forward whereas in example 2, include is used. There are a few characteristics of these two methods.
1. The ServletRequest’s path elements and parameters remain unchanged from the caller’s
2. The included servlet cannot set headers
3. The servlet cannot change the response status code
4. The best way to send information from the calling servlet to the called servlet is using a query string or a better way would be to use the setAttribute() to set values into the request object and use it in the target servlet.
5. And finally, there is also a matter of timing that we need to consider. You can call an include anytime, but the forward has to be called before the response is committed. Otherwise you will end up getting an IllegalStateException.

Regarding the forward method, one reason you may want to use it is so you can dedicate a servlet as the controller. In this way, the controller can filter, preprocess requests, and manage the transaction. The gotcha here is once a servlet forwards a request, it loses control. The controller has no capability to regain access directly. You can create an architecture where requests are returned (forwarded back by a slave servlet), but the native functionality isn't helpful for this.

There is another problem which you need to remember for the exam. When you use the forward method, the URL in the address bar doesn't change. The client loses path information when it receives a forwarded request. That means all relative URLs in the HTML become invalid. Your browser will consider the links broken. Sometimes this doesn't matter, but when it does, you can use sendRedirect() instead.

Exam Trivia:
ServletContext.getRequestDispatcher()— This method uses absolute paths.
ServletRequest.getRequestDispatcher(String path)— The path may be relative, but cannot extend outside current servlet context.
ServletRequest.getNamedDispatcher(String name)— This name is the name of the servlet for which a dispatcher is requested, and is in the web.xml file


from: http://inheritingjava.blogspot.com/2011/03/chapter-18-using-requestdispatcher.html 

Monday, November 21, 2011

QUOTE: Designing a product is keeping five thousand…


QUOTE: Designing a product is keeping five thousand…
Published on Signal vs. Noise | shared via feedly mobile

Designing a product is keeping five thousand things in your brain and fitting them all together in new and different ways to get what you want. And every day you discover something new that is a new problem or a new opportunity to fit these things together a little differently.

And it's that process that is the magic.

—Steve Jobs (via Daring Fireball)




Sent from my iPhone

VIDEO: Inspiring stuff. Related SvN posts: The first…


VIDEO: Inspiring stuff. Related SvN posts: The first…
Published on Signal vs. Noise | shared via feedly mobile

Inspiring stuff. Related SvN posts: The first step is to start and Four tips for learning how to program




Sent from my iPhone

Getting Started With bbPress



Getting Started With bbPress
Published on Smashing Magazine Feed | shared via feedly mobile
Forums have been around forever, so it should come as no surprise that several plugins for the popular publishing platform WordPress provide this feature, as well as support for integrating other forum software. One project, however, has a special place in the WordPress community, and that is bbPress. This is the software created by WordPress founder, Matt Mullenweg, as a lightweight system for the WordPress.org support forums. In true open-source fashion, the bbPress project was born (at bbpress.org, of course) as a lightweight standalone alternative for forums.

Free Icon Set For Web Designers: Aroma (250+ PNG Icons)



Free Icon Set For Web Designers: Aroma (250+ PNG Icons)
Published on Smashing Magazine Feed | shared via feedly mobile


Today we are delighted to release another freebie for our design community. There are many free icon sets out there, and there are quite many commercial ones as well. Yet a good, consistently designed icon set is always a welcome addition to any designer's toolbox. Oliver Twardowski had released the Ultimate Free Web Designer's Icon Set (750 icons, including PSD sources) in the past, and this time he has prepared a fresh, new icon set which contains over 250 original high quality PNGs. Please notice that some icons may be similar to the ones released in the previous set.

HTML5 Semantics



HTML5 Semantics
Published on Smashing Magazine Feed | shared via feedly mobile
Much of the excitement we've seen so far about HTML5 has been for the new APIs: local storage, application cache, Web workers, 2-D drawing and the like. But let's not overlook that HTML5 brings us 30 new elements to mark up documents and applications, boosting the total number of elements available to us to over 100.
Sexy yet hollow demos aside, even the most JavaScript-astic Web 2.0-alicious application will likely have textual content that needs to be marked up sensibly, so let's look at some of the new elements to make sure that your next project is as semantic as it is interactive.

Which Custom Web Fonts Solution Should You Use?


Which Custom Web Fonts Solution Should You Use?
Published on Line25 | shared via feedly mobile

Over the past few years the number of fonts available for use in web design has dramatically increased. It wasn't long ago that we all knew not to stray further than the basic Arial, Helvetica, Times, Georgia mix, but now there's a range of services that allow the use of almost any font imaginable in your website design. This post rounds up the various custom web font solutions and looks at the pros and cons of each.

@font-face

@font-face

The most basic solution out of the lot is the CSS3 @font-face property. I'm sure we're all familiar with @font-face by now, it allows you to load a font file from your CSS and apply that font to the styling of your HTML text.

Pros:

  • Powered by CSS. No Javascript or Flash
  • Completely accessible
  • Easy to implement without external plugins

Cons:

  • Limited to open source fonts

Links:

Google Web Fonts

Google Web Fonts

Since Google launched its Google Web Fonts API the service has grown to include hundreds of freely available fonts for use in your designs. The service was a hit from the start even with its small introductory collection, but now there's a whole library of styles available it's certainly one of the best custom font solutions.

Pros:

  • Powered by CSS. No Javascript or Flash
  • Completely accessible
  • Google hosted fonts are often cached and load very fast
  • Easy to implement through Google's Web Fonts library

Cons:

  • Choice is limited to a range of free fonts

Links:

Typekit

Typekit

For those needing professional or classic fonts in their designs for corporate branding, Typekit is definitely the best solution. Unlike other free services, Typekit allows the embedding of popular premium fonts such as Futura, Meta and Cocon.

Pros:

  • Largest library of fonts, including classic typefaces
  • Service has been acquired by Adobe, which suggests it will be reliable
  • Easy to implement through Typekit's online interface

Cons:

  • Premium service with a yearly fee

Links:

Cufon

Cufon

Nowadays Cufon is overshadowed by the larger custom web font services, but it was a pretty useful resource when it was first launched. Cufon is Javascript powered which makes it great for compatibility across older browsers that don't support @font-face, but it comes with a few disadvantages of its own.

Pros:

  • Good cross browser support
  • Character set can be limited for a smaller file size

Cons:

  • Text is not selectable
  • Should only be used for headers, not body text
  • Limited to open source fonts

Links:

sIFR

sIFR

When sIFR was first introduced many years ago it was a groundbreaking addition to the web designer's toolbox. Nowadays the Flash technology behind sIFR just isn't up to par accessibility and performance wise when compared to the newer alternative soltuions.

Pros:

  • Almost any font can be embedded, including the classics
  • Text remains selectable

Cons:

  • Flash based technology is slow and heavy
  • Won't work on Apple devices
  • Difficult to implement

Links:

Typeface.js

Typeface.js

Typeface.js was released as a viable alternative to sIFR and FLIR as it didn't require any additional technologies such as Flash or PHP with it being entirely Javascript based.

Pros:

  • Good cross browser support
  • Easy to implement with a couple of Javascript links

Cons:

  • Outputs text as an image, which means it isn't selectable
  • Should only be used for headers, not body text
  • Limited to open source fonts

Links:




Sent from my iPhone

Data Monday: More on Mobile


Data Monday: More on Mobile

Looking forward, the majority of Internet use will come from mobile devices (its already happened in some places). But even today some services are beginning to see more of their traffic come from mobile devices than desktops and laptops. Here's a few examples.

  • 55% of Twitter's traffic comes from mobile devices. (source)
  • 60% of Pandora's traffic comes from mobile devices. (source)
  • The Weather Channel registered 1.1 billion online page views in October and 1.3 billion page views on mobile devices. (source)
  • Movie ticketing service Fandango is getting close with 40% of their traffic on mobile. (source)
  • Facebook is also on it's way with 33% of total traffic on mobile. (source)

It's quite likely these numbers are just the start. Japan has been ahead of the World in mobile for many years. Mixi, the top social networking site in Japan is an indicator of how far things can go. Four and a half years ago, 14% of Mixi's page views were on mobile. Today, 85% of page views are on mobile. When your numbers look like that, mobile first thinking makes a ton of sense.


Tags: , ,




Sent from my iPhone

Is this Nikon's D800 DSLR?



Published on Engadget | shared via feedly mobile
Grab the salt shaker folks -- if Nikon Rumors is to be believed, what you're gazing at is Nikon's hotly rumored D800 DSLR. The camera is reportedly packing goodies like a massive 36 megapixel sensor capable of 7360 × 4912 resolution, and an ISO range of 100 to 6,400 that's pushable to 25,600. Furthermore, you can expect to find the same 51-point AF system found in the D3s, slots for SD and CF cards, USB 3.0 connectivity and over three-inches of display on back -- all while being "smaller and lighter" than the current D700. Notably, Nikon is apparently stepping up its DSLR video chops with this cam as well, as it's said to be capable of filming 1080p HD video at 30 fps, while 720p grants you up to 60 fps. Of course, this type of primo kit won't come cheap -- if it all proves true you can expect to slap down roughly $3,900 (¥300,000) to make one yours, although, a release date is still anyone's guess. You'll find another shot of this purported beauty after the break and the full rumor rundown at the source link below.
Continue reading Is this Nikon's D800 DSLR?
Is this Nikon's D800 DSLR? originally appeared on Engadget on Sun, 20 Nov 2011 04:12:00 EDT. Please see our terms for use of feeds.
Permalink The VergesourceNikon RumorsEmail this | Comments



Sent from my iPhone

Saturday, November 19, 2011

Tomcat Error in Eclipse: Cannot create a server using the selected type

Some times if we delete the servers configuration in the workspace or if we move the workspace adding tomcat as server can become difficult thing.  We will hit with the error Cannot create a server using the selected type.
To resolve this error, try one or all of the following:
1.  Go to Window–>Preferences–>Server–>Runtime Environments and fix the broken path/link for the server
2. Rename the org.eclipse.jst.server.tomcat.core.prefs to org.eclipse.jst.server.tomcat.core.prefs.bak (or you can delete this file). This file can be found at \workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings
3.  Rename the org.eclipse.wst.server.core.prefs toorg.eclipse.wst.server.core.prefs.bak (or delete the file).  This file also can be found at the same location as above

from: http://hariprasad.info/cannot-create-a-server-using-the-selected-type-eclipse-tomcat/

Tuesday, November 15, 2011

jQuery 简单实现select二级联动


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jQuery 二级联动</title>
<script src="http://wlog.cn/lib/jquery/jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript">
       $(document).ready(function(){
           $("#province").change(function(){
               $("#province option").each(function(i,o){
                   if($(this).attr("selected"))
                   {
                       $(".city").hide();
                       $(".city").eq(i).show();
                   }
               });
           });
           $("#province").change();
       });
</script>
</head>
<body>
   <select id="province">
       <option>----请选择省份----</option>
       <option>北京</option>
       <option>上海</option>
       <option>江苏</option>
   </select>
   <select class="city">
     <option>----请选择城市----</option>
   </select>
   <select class="city">
       <option>东城</option>
       <option>西城</option>
       <option>崇文</option>
       <option>宣武</option>
       <option>朝阳</option>
   </select>  
   <select class="city">
       <option>黄浦</option>
       <option>卢湾</option>
       <option>徐汇</option>
       <option>长宁</option>
       <option>静安</option>
   </select>
   <select class="city">
       <option>南京</option>
       <option>镇江</option>
       <option>苏州</option>
       <option>南通</option>
       <option>扬州</option>
   </select>
</body>
</html>

Sunday, November 13, 2011

Facade vs. factory

Factory is used when we want to take control of object instantiation, for example if our component works with a set of related or dependent objects we define an interface with CreateXXX() methods.This ensures we don't have "x = new XXX();" scattered through our code, but x = factory.CreateXXX(); - complete control of every created instance outside the component (which enables our component to work with different sets of classes). This is "Abstract Factory" creational pattern.

Facade is a "structural pattern" used to simplify some otherwise complex interfaces. For example, you make a list of all types of emails your applications will send (Welcome, ForgotPassword, NewComment) and create MailFacade class with a method for each email type. This way, client code has only "high level" knowledge about "email types", but not about how these are composed and sent.

web.xml 中的listener、 filter、servlet 加载顺序及其详解

在项目中总会遇到一些关于加载的优先级问题,近期也同样遇到过类似的,所以自己查找资料总结了下,下面有些是转载其他人的,毕竟人家写的不错,自己也就不重复造轮子了,只是略加点了自己的修饰。

首先可以肯定的是,加载顺序与它们在 web.xml 文件中的先后顺序无关。即不会因为 filter 写在 listener 的前面而会先加载 filter。最终得出的结论是:listener -> filter -> servlet

同时还存在着这样一种配置节:context-param,它用于向 ServletContext 提供键值对,即应用程序上下文信息。我们的 listener, filter 等在初始化时会用到这些上下文中的信息,那么 context-param 配置节是不是应该写在 listener 配置节前呢?实际上 context-param 配置节可写在任意位置,因此真正的加载顺序为:context-param -> listener -> filter -> servlet

对于某类配置节而言,与它们出现的顺序是有关的。以 filter 为例,web.xml 中当然可以定义多个 filter,与 filter 相关的一个配置节是 filter-mapping,这里一定要注意,对于拥有相同 filter-name 的 filter 和 filter-mapping 配置节而言,filter-mapping 必须出现在 filter 之后,否则当解析到 filter-mapping 时,它所对应的 filter-name 还未定义。web 容器启动时初始化每个 filter 时,是按照 filter 配置节出现的顺序来初始化的,当请求资源匹配多个 filter-mapping 时,filter 拦截资源是按照 filter-mapping 配置节出现的顺序来依次调用 doFilter() 方法的。

servlet 同 filter 类似,此处不再赘述。

由此,可以看出,web.xml 的加载顺序是:context-param -> listener -> filter -> servlet ,而同个类型之间的实际程序调用的时候的顺序是根据对应的 mapping 的顺序进行调用的。



web.xml文件详解

Xml代码
Web.xml常用元素

定义了WEB应用的名字
声明WEB应用的描述信息

context-param元素声明应用范围内的初始化参数。
过滤器元素将一个名字与一个实现javax.servlet.Filter接口的类相关联。
一旦命名了一个过滤器,就要利用filter-mapping元素把它与一个或多个servlet或JSP页面相关联。
servlet API的版本2.3增加了对事件监听程序的支持,事件监听程序在建立、修改和删除会话或servlet环境时得到通知。
Listener元素指出事件监听程序类。
在向servlet或JSP页面制定初始化参数或定制URL时,必须首先命名servlet或JSP页面。Servlet元素就是用来完成此项任务的。
服务器一般为servlet提供一个缺省的URL:http://host/webAppPrefix/servlet/ServletName。
但是,常常会更改这个URL,以便servlet可以访问初始化参数或更容易地处理相对URL。在更改缺省URL时,使用servlet-mapping元素。

如果某个会话在一定时间内未被访问,服务器可以抛弃它以节省内存。
可通过使用HttpSession的setMaxInactiveInterval方法明确设置单个会话对象的超时值,或者可利用session-config元素制定缺省超时值。

如果Web应用具有想到特殊的文件,希望能保证给他们分配特定的MIME类型,则mime-mapping元素提供这种保证。
指示服务器在收到引用一个目录名而不是文件名的URL时,使用哪个文件。
在返回特定HTTP状态代码时,或者特定类型的异常被抛出时,能够制定将要显示的页面。
对标记库描述符文件(Tag Libraryu Descriptor file)指定别名。此功能使你能够更改TLD文件的位置,
而不用编辑使用这些文件的JSP页面。
声明与资源相关的一个管理对象。
声明一个资源工厂使用的外部资源。
制定应该保护的URL。它与login-config元素联合使用
指定服务器应该怎样给试图访问受保护页面的用户授权。它与sercurity-constraint元素联合使用。
给出安全角色的一个列表,这些角色将出现在servlet元素内的security-role-ref元素
的role-name子元素中。分别地声明角色可使高级IDE处理安全信息更为容易。
声明Web应用的环境项。
声明一个EJB的主目录的引用。
< ejb-local-ref>声明一个EJB的本地主目录的应用。



相应元素配置

1、Web应用图标:指出IDE和GUI工具用来表示Web应用的大图标和小图标

/images/app_small.gif
/images/app_large.gif

2、Web 应用名称:提供GUI工具可能会用来标记这个特定的Web应用的一个名称
Tomcat Example
3、Web 应用描述: 给出于此相关的说明性文本
Tomcat Example servlets and JSP pages.
4、上下文参数:声明应用范围内的初始化参数。

ContextParameter
testIt is a test parameter.

在servlet里面可以通过getServletContext().getInitParameter("context/param")得到

5、过滤器配置:将一个名字与一个实现javaxs.servlet.Filter接口的类相关联。

setCharacterEncoding
com.myTest.setCharacterEncodingFilter

encodingGB2312



setCharacterEncoding
/*

6、监听器配置

listener.SessionListener

7、Servlet配置
基本配置

snoop
SnoopServlet


snoop
/snoop

高级配置

snoop
SnoopServlet

foobar


Security role for anonymous access
tomcat



snoop
/snoop

元素说明
用来声明一个servlet的数据,主要有以下子元素:
指定servlet的名称
指定servlet的类名称
指定web站台中的某个JSP网页的完整路径
用来定义参数,可有多个init-param。在servlet类中通过getInitParamenter(String name)方法访问初始化参数
指定当Web应用启动时,装载Servlet的次序。
当值为正数或零时:Servlet容器先加载数值小的servlet,再依次加载其他数值大的servlet.
当值为负或未定义:Servlet容器将在Web客户首次访问这个servlet时加载它
用来定义servlet所对应的URL,包含两个子元素
指定servlet的名称
指定servlet所对应的URL
8、会话超时配置(单位为分钟)

120

9、MIME类型配置

htm
text/html

10、指定欢迎文件页配置

index.jsp
index.html
index.htm

11、配置错误页面
一、 通过错误码来配置error-page

404
/NotFound.jsp

上面配置了当系统发生404错误时,跳转到错误处理页面NotFound.jsp。
二、通过异常的类型配置error-page

java.lang.NullException
/error.jsp

上面配置了当系统发生java.lang.NullException(即空指针异常)时,跳转到错误处理页面error.jsp
12、TLD配置

http://jakarta.apache.org/tomcat/debug-taglib
/WEB-INF/jsp/debug-taglib.tld

如果MyEclipse一直在报错,应该把 放到


http://jakarta.apache.org/tomcat/debug-taglib
/WEB-INF/pager-taglib.tld


13、资源管理对象配置

jms/StockQueue

14、资源工厂配置

mail/Session
javax.mail.Session
Container

配置数据库连接池就可在此配置:

JNDI JDBC DataSource of shop
jdbc/sample_db
javax.sql.DataSource
Container

15、安全限制配置

Example Security Constraint

Protected Area
/jsp/security/protected/*
DELETE
GET
POST
PUT


tomcat
role1


16、登陆验证配置

FORM
Example-Based Authentiation Area
/jsp/security/protected/login.jsp/jsp/security/protected/error.jsp

17、安全角色:security-role元素给出安全角色的一个列表,这些角色将出现在servlet元素内的security-role-ref元素的role-name子元素中。
分别地声明角色可使高级IDE处理安全信息更为容易。

tomcat

18、Web环境参数:env-entry元素声明Web应用的环境项

minExemptions
1
java.lang.Integer

19、EJB 声明

Example EJB reference
ejb/Account
Entity
com.mycompany.mypackage.AccountHome
com.mycompany.mypackage.Account

20、本地EJB声明

Example Loacal EJB reference
ejb/ProcessOrder
Session
com.mycompany.mypackage.ProcessOrderHome
com.mycompany.mypackage.ProcessOrder

21、配置DWR

dwr-invoker
uk.ltd.getahead.dwr.DWRServlet


dwr-invoker
/dwr/*

22、配置Struts
Struts Blank Application

action

org.apache.struts.action.ActionServlet


detail2


debug2


config/WEB-INF/struts-config.xml


applicationApplicationResources

2


action
*.do


index.jsp




struts-bean
/WEB-INF/tld/struts-bean.tld


struts-html
/WEB-INF/tld/struts-html.tld


struts-nested
/WEB-INF/tld/struts-nested.tld


struts-logic
/WEB-INF/tld/struts-logic.tld


struts-tiles
/WEB-INF/tld/struts-tiles.tld

23、配置Spring(基本上都是在Struts中配置的)



contextConfigLocation/WEB-INF/applicationContext.xml, /WEB-INF/action-servlet.xml





org.springframework.web.context.ContextLoaderListener




org.springframework.web.context.request.RequestContextListener


from: http://zhxing.javaeye.com/blog/399668

Saturday, November 12, 2011

Domain Driven Design and Development In Practice

(from:http://www.infoq.com/articles/ddd-in-practice   )

Background

Domain Driven Design (DDD) is about mapping business domain concepts into software artifacts. Most of the writings and articles on this topic have been based on Eric Evans' book "Domain Driven Design", covering the domain modeling and design aspects mainly from a conceptual and design stand-point. These writings discuss the main elements of DDD such as Entity, Value Object, Service etc or they talk about concepts like Ubiquitous Language, Bounded Context and Anti-Corruption Layer.

Wednesday, November 9, 2011

Adobe confirms Flash Player is dead for mobile devices


 
Adobe confirms Flash Player is dead for mobile devices
Published on Engadget | shared via feedly mobile
We heard the talk and now here's the confirmation: Flash Player for mobile devices is officially dead. Adobe is reaffirming its commitment to "aggressively contribute" to HTML5, a platform with broader support and capabilities than Flash was ever able to deliver. Adobe will of course also be pushing developers to work in its AIR platform for a more native experience, and the company will continue to work on Flash Player for desktop operating systems, but one can't help but see the platform as a whole standing on fairly shaky footing at this point.

Adobe confirms Flash Player is dead for mobile devices originally appeared on Engadget on Wed, 09 Nov 2011 09:47:00 EDT. Please see our terms for use of feeds.

Permalink | sourceAdobeEmail this | Comments



Sent from my iPhone

Monday, November 7, 2011

How To Encrypt Just Mail's Messages

This is kind of crazy, but it works like a charm. I was trying to find a way to just encrypt and password-protect my mail without going and putting my account in FileVault (evil). I noticed that Mac OS X would mount a disk image to open a program it knew was once on that disk image and, well, I put two and two together: what if my mail was on an encrypted disk image that also held the only working copy of the Mail application? Well, it would prompt for the image password, open Mail, and if I’d done things right then my mail would show up.
So that’s what I did.

Make the Image

You’ll need an encrypted disk image with your current mail accounts. Don’t use Disk Utility for this because its “Image from Folder” feature creates a static image and we want a sparse image. Do something like this:
$ cd Library
$ hdiutil create -size 2g -srcfolder Mail -format SPARSE -encryption -stdinpass Mail
Enter disk image passphrase:
....................................
created: /Users/ahknight/Library/Mail.sparseimage

Link the Image

For now, let’s just move the Library/Mail folder to the side rather than deleting it outright. Rename it to Mail-old or something. Then, open the image you just made (if you did the above, it’s in ~/Library/Mail.sparseimage) and then do the following:
$ ln -s /Volumes/Mail ~/Library/Mail
Now when Mail wants to use your mail, it will use the image. Of course, if you start mail without the image mounted you’ll get strange things happening, so we need to put Mail on the image.

Add and Lock Mail

Drag a copy of Mail into the image. Remove the Mail item from your Dock and add this copy to it instead (this is the important step). Now when you click on Mail, the system will know to go to this disk image.
However, if any other copy of Mail is available, it will go to that one, instead. To prevent this, we have to make the other Mail ineligible for launching in one way or another. Pick one:
  • Delete it off the system and symlink /Applications/Mail.app to the copy on the disk image while it’s mounted, and have the image mounted during updates (best idea, since it doesn’t break anything so long as the image is mounted)
  • sudo chown root /Applications/Mail.app; sudo chmod 700 /Applications/Mail.app and copy the program back to the image after updates
  • Trash it. You’ll need to copy it off the image and back into place before system updates and then back on the image when done updating.
The first is the easiest and preferable way to do it.

Test

Now the moment of truth. Unmount the image and then click on the Mail icon. You should get a password prompt for the image and then Mail should start with all of your mail.



from: http://www.macgeekery.com/hacks/software/how_to_encrypt_just_mails_messages

Saving Data Using JSTL in a JSP Page

When a JSP page needs to save data for its processing, it must specify a location, called the scope. See Saving Data in a JSP Page for an explanation of the four available scopes.
Data is saved using a mechanism called scoped variables. A scoped variable has a name, which is of type Stringand a value, which is of type Object. For non-page scoped variables, it is recommended that the name use the reverse domain name convention (e.g., prefixed with com_mycompany) to minimize unexpected collisions when integrating with third party modules.
When using the JSTL's expression language (see Enabling the JSTL Expression Language in a JSP Page), the variables in each scope are made available in the implicit objects pageScoperequestScopesessionScope, andapplicationScope.
This example saves and retrieves values in scoped variables in each of the four scopes:
<%-- Declare the core library --%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>

<%-- Save data in scoped variables --%>
<c:set var="name1" value="value1" scope="page" />
<c:set var="com_mycompany_name2" value="value2" scope="request" />
<c:set var="com_mycompany_name3" value="value3" scope="session" />
<c:set var="com_mycompany_name4" value="value4" scope="application" />

<%-- Show the saved values --%>
<c:out value='${pageScope.name1}' />
<c:out value='${requestScope.com_mycompany_name2}' />
<c:out value='${sessionScope.com_mycompany_name3}' />
<c:out value='${applicationScope.com_mycompany_name4}' />
When retrieving a saved value, it is possible to omit the scope. If the scope is omitted, the variable name is automatically searched for in each of the scopes, in the order pageScoperequestScopesessionScope, andapplicationScope.
<%-- Show the saved values without a specific scope --%>
<c:out value='${name1}' />
<c:out value='${com_mycompany_name2}' />
<c:out value='${com_mycompany_name3}' />
<c:out value='${com_mycompany_name4}' />
It is also possible to specify the value to save using the contents of the body, rather than through the value attribute:
<%-- Save data using body content --%>
<c:set var="name1" scope="page">
    value 1 in body
</c:set>
<c:set var="com_mycompany_name2" scope="request" >
    value 2 in body
</c:set>
<c:set var="com_mycompany_name3" scope="session" >
    value 3 in body
</c:set>
<c:set var="com_mycompany_name4" scope="application">
    value 4 in body
</c:set>
When specifying the value using body contents, the body contents is first trimmed of leading and trailing white space before it is saved. For example,
<c:set var="name1" scope="page">
    line 1
    line 2
</c:set>
would be saved as:
"line 1\n    line 2"