JSP and JavaBean

  JSP and JavaBean 
  JSP development portal (Author: IDEAL at 18:15 on August 10, 2000) 

  Although you can file in small orders Add a large piece of the code, but most of the Java programming code are reusable components can be called JavaBean.    ActiveX controls JavaBean told the same: they provide the known function, and is ready to repeat the use of the purpose of design. 

  JavaBean value is that it may be able to use a group of properties, and these properties will provide access to JavaBean set.    For example to the people, this person is JavaBean, and his name, social welfare safety numbers, and addresses can be characteristics.    The JSP web site, you will be basically 'JavaBean' dynamic linking to your site. 

  JavaBean assumption in the establishment of the website is built, you want to do the first thing is to tell it to use JSP page JavaBean. This work can be used <jsp: useBean> tag to complete: <jsp: useBean id = " localName "class =" com.jguru.Person "scope =" application "/>. 

  <jsp:useBean> Label id attributes you need to identify beans. Here, you provide a name for JSP page to identify beans, in addition to id attribute, you must also tell the website to Daonailiquhua beans, or It is the Java category name.    Attribute types provided in the various methods of how to find it, the final component is a necessary attribute scope. Attributes with the help of the scope, you can tell beans, it should be a single page (the default) [scope = "page" ;] as a requested web page [scope = "request"]; calls for the period of [scope = "session"]; or for the entire application process [scope = "application"] to safeguard its own information, the terms of the scope of calls , you can easily JSP page in the maintenance of the project, such as Cart. 

  But you declaration of a JavaBean, you can access it on the characteristics of setting it.    To achieve a value of the properties, the use of <jsp: getProperty> tags.    With <jsp: getProperty> tag, you can specify the name to be used beans (from the id useBean field), and you want to obtain value of the properties.    Then, the real value will be on the output of: <jsp: getProperty id = "localName" property = "name" />. 

  To change the characteristics of JavaBean, you need to use <jsp: setProperty> tags. On the label, you also need to identify the beans as well as the characteristics of that, in addition, you also need to provide a new value. Naming If correct, these can be directly in the format specified by: <jsp: setProperty id = "localName" property = "*" />; 

  Parameters obtained from one, you have to direct this feature, as well as named parameters: <jsp:setProperty id="localName" property="address" param="parameterName" />; 

  Or directly to the name and the value set: <jsp:setProperty id="localName" property="serialNumber" value="string" /> or <jsp: setProperty id = "localName" property = "serialNumber" value = < %% = expression> />. 

  JavaBean the final point: let JavaBean network server can be found, you will need the type of files on the special place.    JSWDK on, the simplest places in the installation directory, the directory of categories, such as \ jswdk-1.0.1 \ classes. 

"Expert One-on-One J2EE Development without EJB" Douhougan

  "Expert One-on-One J2EE Development without EJB" Douhougan 
  —-** In 2006/01/14 

  Heard "Expert One-on-One J2EE Development without EJB" has been a very long time.    However, as time has been very tight, (mainly did not have time), this does not present a good opportunity to read the book carefully. 
  In this semester final exams finished, a lot of time on their own, so in the last few days in this book a good read. 
  This book is the English version.    Read a bit difficult.    But also good exercise their abilities. 
  Read after they found their ability Chatache the.    The author's vision of capacity.    Gave me great inspiration. 
  The author J2EE development on all aspects, including the realization of the various layers, as well as the shortcomings of their existence, 
  At the same time give some solutions.    As described in the author at the same time, the light of their own experience in the exposition, there are also a lot of advantages and evidence. 
  In the web layer, the major way to achieve this, as well as their shortcomings and correct programme. 
  In the middle layer, the realization of any major, as well as their shortcomings and correct programme. 
  In the persistence layer, the major way to achieve this, as well as their shortcomings and correct programme. 
  EJB caused by the use of the consequences.    EJB use of the main field.    SLSB use.    Spring used EJB or other alternative technologies provided by the service. 
  EJB caused by the introduction of the complexity and difficulty in testing, and other issues. 
  IoC the introduction of the powerful advantage. 
  AOP the introduction of the powerful advantage. 
  TDD (Test Drivren Development) benefits, as well as how to provide better application development based on the test. 
……
  Through a lot of technology, the introduction of open source products.    The author's views are certainly a lot of people agree, although some of the practical implementation of standards will affect product development.    However, the author can be seen in the language, the author's aim is to develop better maintainability, testability better, more simple applications.    Rather than a product provider or deny the unilateral introduction.    Can be seen from the starting point is right.    I believe in the near future, Rod Johnson will leave you better know. 

  Look forward to.    In the hope that he can better development of the J2EE to the author of the study, all the best people to learn.    Let their products more outstanding. 
  Have fun! 

Thread safe tips for python extending

  In fact, the habit of using python write some single-threaded expansion, has not encountered such problems 

  Write a python today in the extension of the time encountered a problem. Through the python launched a c + + thread, the thread c + + will be a pullback python interface. Debugging has been for a long time is not aware of the security thread reasons, because c + + threads in the vm call python when the pyobject. thread is not safe. Therefore, when c + + threading operation vm directly to a certain object it is very wrong result. 

  I search the information in the http://www.python.org/dev/peps/pep-0311/ have talked about how the vm synchronous python. Two vm lock function can be done, and c + + thread synchronization. Is The so-called GIL (Global Interpreter Lock). 
  There are two ways to accomplish the following: 
  1. Py_BEGIN_ALLOW_THREADS, Py_END_ALLOW_THREADS this to Acer 
  2. PyGILState_Ensure and PyGILState_Release 

  But I Py_BEGIN_ALLOW_THREADS not seem useful, I will not have to get to the bottom, because PyGILState_Ensure enough. Do not have too much time to study the documents, to use the time to look back on. 

  I look at the sample code: 

  # Include "Python.h" 
  # Include "ceval.h" 

  Class PyGILHelper 
  ( 
  Public: 
  PyGILHelper (): 
  MState (PyGILState_Ensure ()) 
  ( 
  ) 
  ~ PyGILHelper () 
  ( 
  PyGILState_Release (mState); 
  ) 
  Protected: 
  PyGILState_STATE mState; 
  ); 

  Usage is simple: 

  PyGILHelper lock; 
  / / Some c api code 

Enoeht the Java source code Series (2) - Comprehensive plant

  Package org.kyle.net.svr.sample; 

  Public class IntegrationFactory 

  ( 

  Public IntegrationFactory () 

  ( 

  ) 

  Public static IListener createListener (GenProfile genCfg) 

  ( 

  IListener iListener = null; 

  Try ( 

  / / Configuration file set up under the category creates corresponding examples 

  IListener = (IListener) instantiateIt (genCfg.getListenerImpl ()); 

  ) 

  Catch (Exception e) ( 

  Debug.info ( "Listener class not found!"); 

  / / If the designated categories do not exist, use the default category to create examples, as well as because of the procedure used in the interface are therefore here to provide a default category invoked, the compiler compiler, and only mainclass, the need for a separate again the compiler default category 

  IListener = new SampleListenerImpl (); 

  ) 

  Return iListener; 

  ) 

  / / In accordance with the category names are examples of 

  Public static Object instantiateIt (String clsName) 

  Throws ClassNotFoundException, 

ClassCastException,

InstantiationException,

IllegalAccessException

  ( 

  Class cls = Class.forName (clsName); 

  Return cls.newInstance (); 

  ) 

  ) 

  In the configuration file, add the following: Listener = org.kyle.net.svr.sample.SampleListenerImpl 

JMF capture technology (audio)

  JMF capture technology (audio) 

  JMF can capture voice and video equipment, also can be controlled by means of the JMF Mike, these audio and video camera equipment, to be discussed here is how to make use of JMF Mike, in their own tests on the machines, let you hear their own voices. 

  Below is related to the main categories: 

  CaptureDeviceManager, CaptureDeviceInfo, Vector, MediaPlayer, DataSource, MeidaLocator, AduioFormat, VideoFormat, Format. 

  Sun can be provided in the Document on the inspection can be down under, the site not remember.    Can be looked at, there was a preliminary understanding, and then return to read examples of class libraries, this might be better. 

  Public class CaptureDeviceManager 

  Extends java.lang.Object 

  CaptureDeviceManager is a manager class that provides access to a list of the capture devices available on a system. CaptureDeviceManager uses a registry and query mechanisms to locate devices and return CaptureDeviceInfo objects for available devices. The CaptureDeviceManager is also used to register new capture devices. 

  Public class CaptureDeviceInfo 

  Extends java.lang.Object 

  Implements java.io.Serializable 

  A CaptureDeviceInfo object contains information about a particular capture device. 

  Public class MediaPlayer 

  Extends java.awt.Container 

  Implements Player, java.io.Externalizable 

  MediaPlayer encapsulates a player in a JavaBeans TM component. MediaPlayer implements the Player and Externalizable interfaces. 

  A MediaPlayer can be used as a full-featured Player with either the default Player controls or custom controls. 

  Also involves a monitoring interface: 

  ControllerListener.    This is mainly used to monitor the media player interface. 

  1, capture audio equipment 

  / * 

  * @ Author: kenny 

  * / 

  Import javax.media .*; 

………………..

  (Public class CaptureAudio 

  Vector deviceList = new Vector (); 

  AudioForamt audio = new AudioFormat (AudioFormat.LINEAR); 

  Format audioFormat = (Format) audio; 

  MediaPlayer player = null; 

  MediaLocator locator = null; 

  CaptureDeviceInfo captureInfo; 

  Public CaptureAudio () ( 

  DeviceList = CaptureDeviceManager.getDeviceList (audioFormat); 

  CaptureInfo = (CaptureDeviceInfo) deviceList.get (0); 

  CaptureInfo.getLocator locator = (); 

  ) 

  Public void play () ( 

  Player = new MediaPlayer (); 

  Player.setMediaLocator (locator); 

  Player.addControllerListener (this); 

  Player.realize (); 

  ) 

  Public void controllerUpdate (ControllerEvent e) ( 

  If (e instanceof RealizeCompleteEvent) 

  Player.prefetch (); 

  If (e instanceof PrefetchCompleteEvent) 

  Player.start (); 

  ) 

  Public static void main (String [] args) ( 

  CaptureAudio audio = new CaptureAudio (); 

  Audio.play (); 

  ) 

  ) 

1.7 Java Thread Programming

  When multiple threads are interacting with an object, controls need to be in place to ensure that the threads don't adversely affect one another. This chapter deals with issues that can introduce subtle errors in your application. An application that fails to safely control concurrent access can work properly most of the time-maybe nearly all the time - but will occasionally produce erroneous results. This makes the understanding and disciplined use of the information in this chapter critical to writing truly thread-safe applications that work properly all the time. 
  If you have a system in a baffling problem, is likely to visit with the issue of Oh 
  Volatile Member Variable Modifier 
  The Java Language Specification indicates that for optimal speed, individual threads are permitted to keep a working copy of shared member variables and only reconcile them with the shared original occasionally. To be more accurate, the word "occasionally" in the last sentence should be replaced with "when a thread enters or leaves a synchronized block of code." I'll tell you more about synchronized blocks later in this chapter. When only one thread is interacting with the member variables of an object, this optimization works very well and can allow for faster execution. When two (or more) threads are simultaneously working with an object, care must be taken to ensure that changes made to a shared member variable by one thread are seen by the other. 
  Java specification that, in order to optimize speed, each thread with all members sharing a copy of variables, when the beginning or end of a thread synchronization code block, only to write the variable values.    When single-threaded, the good work of such a mechanism will be entitled to higher performance, but a number of threads to work together, consideration must be given by a thread change public variable to be aware of other threads. 
  The volatile keyword is used as a modifier on member variables to force individual threads to reread the variable's value from shared memory every time the variable is accessed. In addition, individual threads are forced to write changes back to shared memory as soon as they occur. This way, two different threads always see the same value for a member variable at any particular time. Chances are that most of you expected this behavior from the Java VM already. In fact, many experienced Java developers don't understand when the use of volatile is necessary. 
  Volatile keywords, if modified to members of variables, each thread is forced to visit each variable must be re-read, each change variable values to be written as soon as possible.    In this way, two different threads in a specific time can be the same as the total value of the variable 
  Use volatile on member variables that can be accessed by two or more threads unless all the threads access the variables within synchronized blocks of code. If a member variable remains constant after construction (it is read-only), there is no need for it to be volatile. 
  If a member variable is read-only, there is no need to set up volatile 
  If a visit this thread all the variables are in a synchronized block, there is no need to set volatile 
  The volatile modifier exists to request that the VM always access the shared copy of the variable. This is less efficient than allowing the VM to perform optimizations by keeping a private copy. You should use volatile only when it is necessary; overuse will unnecessarily slow the application's execution. 
  Volatile requirements of each virtual machine on the request of variables to visit, for each thread to maintain a private copy is inefficient and will lower speed access, such as non-essential, do not use 
  Synchronized Method Modifier 
  The addition of the synchronized modifier to a method declaration ensures that only one thread is allowed inside the method at a time. This can be useful in keeping out other threads while the state of an object is temporarily inconsistent. 
  Synchronized modification, modification of a method used to declare that can guarantee the same time there is only one thread can call this method. 
  Such a mechanism to prevent objects in a continuous state was no other threads visit 
  Two Threads Simultaneously in the Same Method of One Object 
  If two or more threads are simultaneously inside a method, each thread has its own copy of local variables. 
  Two or more threads at the same time call the same object in the same way, each thread has a copy of the local variables 
  One Thread at a Time 
  More than one thread can be inside a method, and each thread keeps a copy of its own local variables. However, there are times when application constraints require that only one thread be permitted inside a method at a time. 
  When a thread encounters a synchronized instance method, it blocks until it can get exclusive access to the object-level mutex lock. Mutex is short for mutual exclusion. A mutex lock can be held by only one thread at a time. Other threads waiting for the lock will block until it is released. When the lock is released, all the threads waiting for it compete for exclusive access. Only one will be successful, and the other threads will go back into a blocked state waiting for the lock to be released again. 
  Guarantee the same time there is only one thread invoke a method, simply stated before the synchronized method.    When a thread encountered Affirms that the method sychronized example, will be blocked until it was object-level mutex lock signal of access, at a certain moment mutex signal can only be a thread with other waiting for the signal The thread must wait for the signal to be released this mutex lock release, other threads access to competition, the success of threads running other threads continue to wait for the obstruction to release the mutex lock. 
  Two Threads, the Two Objects 
  Every instance of a class has its own object-level lock. 
  Although the doStuff () method is synchronized, there is no competition for exclusive access to the object-level lock. Each instance, obj1 and obj2, has its own object-level lock. When threadA enters the doStuff () method of obj1 (line 1), it acquires exclusive access to the object-level lock for obj1. When threadB enters the doStuff () method of obj2 (line 3), it acquires exclusive access to the object-level lock for obj2. 
  Examples of each object has its own object-level locking.    In other words, the lock is built on the synchronized object instance, and not the object of the abstract.    Call the same number of threads examples of an object with a synchronized way, the visit will be synchronized, and call the same number of threads examples of the different groups with a synchronized way, it is not mutually exclusive of mutual visit. 
  Avoiding Accidental Corruption of an Object 
  It's an unavoidable fact that the object must be in an inconsistent state for a brief period of time, even with everything except the assignments taken out: 
  Public synchronized void setNames (String firstName, String lastName) ( 
  Fname = firstName; 
  Lname = lastName; 
  ) 
  No matter how fast the processor is, it's possible that the thread scheduler could swap out the thread making the changes after it has changed fname but before it has changed lname. Holding an object-level lock does not prevent a thread from being swapped out. And if it is swapped out, it continues to hold the object-level lock. Because of this, care must be taken to ensure that all reads are blocked when the data is in an inconsistent state. CleanRead (see Listing 7.16) simply adds the synchronized method modifier to getNames () to control concurrent reading and writing. 
  Two threads at the same time calling a method of amending certain examples of variable values, values of these variables will lead to a moment in the state is not continuous, synchronized with modified this method, can guarantee that the integrity of this variable value 
  Deferring Access to an Object While It Is Inconsistent 
  Calling a thread in a synchornized value of the modification to set a example of the value of certain variables, only restriction other threads at the same time calling this method, does not restrict other threads calling other means of access these variables, if At this point another thread in the value of the call was a way to visit these variables, some variables may have been modified, and also some other variables have not changed, and may cause variable is discontinuous. 
  Will be worth Xiuchifu synchronized with the former method, solve this problem.    This is because there is only one example of a target object-level locking, when a synchronized method is called, the examples of other synchronized methods must await the release of this lock. 
  If two or more threads might be simultaneously interacting with the member variables of an object, and at least one of those threads might change the values, it is generally a good idea to use synchronized to control concurrent access. If only one thread will be accessing an object, using synchronized is unnecessary and slows execution. 
  Synchronized Statement Block 
  The synchronized block can be used when a whole method does not need to be synchronized or when you want the thread to get an object-level lock on a different object. 
  Synchronized block Scope 
  1, not the entire synchronization methods are needed 
  2, need to lock the different target 
  The synchronized statement block looks like this: 
  Synchronized (obj) ( 
  / / Block of code 
  ) 
  Where obj is a reference to the object whose object-level lock must be acquired before entering the block of code. 
  This setPoint () method 
  Public synchronized void setPoint (int x, int y) ( 
  This.x = x; 
  This.y = y; 
  ) 
  Can be rewritten to instead use a synchronized block: 
  Public void setPoint (int x, int y) ( 
  Synchronized (this) ( 
  This.x = x; 
  This.y = y; 
  ) 
  ) 
  The behavior of both versions of setPoint () is virtually the same. They do compile to different byte-code, but both of them make sure that they have exclusive access to the object-level lock for the instance before making changes to x and y . 
  Reducing the Time That the Lock Is Held 
  A synchronized block can be used to reduce the time that the object-level lock is held. If a method does a lot of other things that don't require access to the member variables, it can shorten the time that it holds the lock to just the critical portion: 
  Public void setValues (int x, double ratio) ( 
  / / Some other, the long-running statements that don't work 
  / / With the member variables go here. 
  / / … 
  Double processedValA = / / … long calculation … 
  Double processedValB = / / … long calculation … 
  / / … 
  Synchronized (this) ( 
  A = processedValA; 
  B = processedValB; 
  ) 
  In setValues (), exclusive access to the object-level lock is not needed until the time-consuming calculations have been made and the results are ready to be stored. At the bottom of the method, the object-level lock is acquired and held briefly to simply assign new values to the member variables a and b. 
  Reduce lock time, only in this way the need for synchronization of locking, and the youngest of locking overhead 
  Locking an Object Other Than this 
  A non-locking the object of this 
  The reference mutex indicates the object whose object-level lock must be acquired before entering the statement block. It can be a reference to any object in the VM, not just this. Regardless of how a thread leaves a synchronized block, it automatically releases the lock. This includes a return statement, a throw statement, or just falling through to the next statement after the block. Calling a method from within the synchronized block does not constitute leaving the block (the lock is still held). 
  Virtual machine can be synchronized with any object, not just this. 
  Sometimes you will need to call two synchronized methods on an object and be sure that no other thread sneaks in between the calls. Consider this code fragment from a class called Bucket: 
  Sometimes two synchronized methods must be implemented simultaneously 
  Public class Bucket extends Object ( 
  / / … 
  Public synchronized boolean isSpaceAvailable () (/ / … 
  Public synchronized void add (BucketItem o) 
  Throws NoSpaceAvailableException (/ / … 
  Public synchronized BucketItem remove () (/ / … 
  / / … 
  ) 
  A call: 
  Bucket b = / / … 
  / / … 
  If (b.isSpaceAvailable ()) ( 
  B.add (item); 
  ) 
  This is fine if only one thread is interacting with this instance of Bucket. But if multiple threads are potentially trying to add BucketItem objects to the same Bucket, a new approach has to be taken to avoid a race condition. Imagine that threadA checks and sees that space is available, but before it actually adds its item, threadB checks and also sees that space is available. Now threadA and threadB are racing to actually add an item. Only one can win the race, and that thread gets to add its item . The other thread will fail to add its item and will throw a NoSpaceAvailableException. To prevent this problem, a synchronized block should be wrapped around the two method calls: 
  This method only when a thread is correct, otherwise they will be in sync errors 
  Bucket b = / / … 
  / / … 
  Synchronized (b) ( 
  If (b.isSpaceAvailable ()) ( 
  B.add (item); 
  ) 
  ) 
  The synchronized block uses the object-level lock on b, the Bucket instance. This is the same lock that must be acquired before entering the isSpaceAvailable () and add () methods. If a thread can get the object-level lock and enter the synchronized block, it is guaranteed to be able to invoke isSpaceAvailable () and add () without blocking. Because it already has the object-level lock for b, there is no delay or competition to enter the synchronized methods. In addition, no other thread can invoke these methods until the first thread leaves the synchronized block. 
  To the code on a b-lock, the other threads can call b synchronized in any way, once a thread was a b lock, the lock will certainly implementation of the code, there are no other threads competition 
  Static synchronized Methods 
  In addition to the object-level lock that exists for each instance of a class, there is a class-level lock that all instances of a particular class share. Every class loaded by the VM has exactly one class-level lock. If a method is both static and synchronized, a thread must get exclusive access to the class-level lock before entering the method. 
  The class-level lock can be used to control concurrent access to static member variables. Just as the object-level lock was needed to prevent data corruption in non-static member variables, the class-level lock is needed to prevent corruption of static member variables. Even when no variables are involved, the synchronized modifier can be used on static methods simply to ensure that only one thread is inside the method at a time. 
  Object-level lock correspond to each category of case 
  Class-level lock all categories corresponding to the example of virtual machine generated each category there is a class-level lock, for a static synchronized method, this method before calling, threading his visit will Pai class-level lock. 
  Using the Class-Level Lock in a synchronized Statement 
  The synchronized statement can also use a class-level lock. This can be useful if a static method runs for a long period of time. Additionally, it can be used to ensure that two static method calls by one thread are not interleaved with a call by another thread. 
  To lock on the class-level lock, use the following code 
  Synchronized (ClassName. class) ( 
  / / Body 
  ) 
  Class-Level Lock used to block synchronization code, the use of synchronized (class names. Class) () 
  Synchronization and the Collections API 
  Vector and Hashtable were originally designed to be multithread-safe. Take Vector, for example - the methods used to add and remove elements are synchronized. If only one thread will ever interact with an instance of Vector, the work required to acquire and release the object-level lock is wasted. 
  Vector and Hashtable initially designed as a thread-safe, most of them are synchronized method, in the single-threaded process is unnecessary 
  The designers of the Collections API wanted to avoid the overhead of synchronization when it wasn't necessary. As a result, none of the methods that alter the contents of a collection are synchronized. If a Collection or Map will be accessed by multiple threads, it should be wrapped by a class that synchronizes all the methods. 
  Collections are not inherently multithread-safe. Extra steps must be taken when more than one thread will be interacting with a collection to make it multithread-safe. 
  Collection API designed for the time when the need for synchronized, the default is not thread-safe, if in a multi-threaded environment using Collection, we must first convert it into thread-safe 
  There are several static methods in the Collections class that are used to wrap unsynchronized collections with synchronized methods: 
  Public static Collection synchronizedCollection (Collection c) 
  Public static List synchronizedList (List l) 
  Public static Map synchronizedMap (Map m) 
  Public static Set synchronizedSet (Set s) 
  Public static SortedMap synchronizedSortedMap (SortedMap sm) 
  Public static SortedSet synchronizedSortedSet (SortedSet ss) 
  Collections provide several static method to be used for non-security thread pool thread-safe set for the conversion, above, apply as follows: 
  Basically, these methods return new classes that have synchronized versions of the collections' methods. To create a List that is multithread-safe and backed by an ArrayList, use the following: 
  List list = Collections.synchronizedList (new ArrayList ()); 
  When synchronizing collections, do not keep any direct reference to the original unsynchronized collection. This will ensure that no other thread accidentally makes uncoordinated changes. 
  In order to ensure synchronization sets, not directly using the initial non-thread-safe set. 
  Safely Copying the Contents of a List into an Array 
  List three ways to copy an array safety 
  Safely Iterating Through the Elements of a Collection 
  Ergodic pool safety, traversing the time to prevent other threads add or modify data collection 
  The elements of a Collection can be stepped through one by one by using an Iterator. In a multithreaded environment, you will generally want to block other threads from adding or removing elements while you are iterating through the current collection of elements. 
Deadlocks
  Using locks to control concurrent access to data is critical to avoid subtle race conditions within applications. However, trouble can arise when a thread needs to hold more than one lock at a time. 
  Control the use of lock mechanism with access critical data when a thread lock at the same time have more than two problems may arise: Deadlock 
  Deadlocks can be extremely difficult to track down. Generally, most of an application will continue to run, but a couple of threads will be stuck in a deadlock. To make matters worse, deadlocks can hide in code for quite a while, waiting for a rare condition to occur. An application can run fine 99 out of 100 times and only deadlock when the thread scheduler happens to run the threads in a slightly different order. Deadlock avoidance is a difficult task. 
  Most code is not vulnerable to deadlocks, but for the code that is, try following these guidelines to help avoid deadlocks: 
  L Hold locks for only the minimal amount of time necessary. Consider using synchronized statement blocks instead of synchronizing the whole method. 
  L Try to write code that does not need to hold more than one lock at a time. If this is unavoidable, try to make sure that threads hold the second lock only for a brief period of time. 
  L Create and use one big lock instead of several small ones. Use this lock for mutual exclusion instead of the object-level locks of the individual objects. 
  L Check out the InterruptibleSyncBlock class in Chapter 17. It uses another object to control concurrent access to a section of code. Additionally, instead of having a thread block on the synchronized statement, the thread is put into a wait-state that is interruptible. I'll tell you more about the wait-notify mechanism in Chapter 8. 
  It is hard to avoid deadlock, the following general principles can reduce the possibility of deadlock 
  L lock the shortest possible time, to make full use of synchronized statement as a whole rather than synchronized methods 
  L at the same time try not to have more than one lock, if unavoidable, should be guaranteed a second thread lock the shortest possible time 
  L establishment of the use of a big lock, rather than a number of small lock, with a new large object lock ghostwriters all the small lock 
  Chapter 17 gives InterruptibleSyncBlock l category, it uses another object code block to control concurrent access.    Do not let a thread synchronization in a statement, obstruction, but may be interrupted at the wait state, the next chapter will discuss the use of the wait-notify mechanism. 
  Speeding Concurrent Access 
  To speed up execution, do not use synchronized unnecessarily. Be sure that it's really needed for proper functioning. If synchronization is necessary, see if using a synchronized statement block would work instead of a synchronized method. Although this won't decrease the cost of acquiring and releasing the lock, it will reduce contention for the lock among the other threads because the lock is held for a shorter period of time. 
  Accelerate the speed of synchronization visit: 
  1, such as non-essential, does not apply synchronized 
  2, the use of synchronized statement block can not use synchronized method will reduce the probability of conflict 
Summary
  In this chapter, I showed you: 
  L How to use volatile to force unsynchronized threads to work with the shared copy of a variable instead of a private working copy. 
  L How to use the synchronized method modifier on non-static methods to require a thread to get exclusive access to the object-level lock before entering the method. 
  L How to use the synchronized statement block to require a thread to get exclusive access to the object-level lock of the specified object before executing the code within the block. 
  L How to use the synchronized method modifier on static methods to require a thread to get exclusive access to the class-level lock before entering the method. 
  L How to work safely with the Collections API in a multithreaded environment. 
  L How to understand the causes of deadlocks, and how to try to avoid them. 
  Guarantee the use of multi-threaded Xiuchifu volatile variables simultaneously 
  Guarantee the use of synchronized Xiuchifu examples of an object in the object-level lock on the synchronization 
  Xiuchifu guarantee the use of synchronized object static method in the class-level lock on the synchronization 
  To ensure the safe use of threads collections, we must first convert the collections generated thread-safe, collections 

Eclipse development struts Complete Guide

  One for the installer 

  1, JDK 5.0 installation program download 

  Download Address: 

  Https: / / jsecom15b.sun.com/ECom/EComActionServlet/DownloadPage: ~: com.sun.sunit.sdlc.content.DownloadPageInfo; jsessionid = 502E87C71D77E3BC297C08B35DAC9AD4; jsessionid = 502E87C71D77E3BC297C08B35DAC9AD4 

  Agree with the agreement, can be downloaded jdk-1_5_0_05-windows-i586-p.exe. 

  2, tomcat 5.5.9 Download 

  Download Address: http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi 

  The latest version is 5.5.11 alpha version because it is beta, so there may be an element of uncertainty, which is why we here to download the 5.5.9 exe. 

  3, Sysdeo Eclipse Tomcat Launcher plugin 3.1beta edition 

  Download Address: http://www.sysdeo.com/eclipse/tomcatplugin 

  TomcatPluginV31beta.zip here to download. 

  4, eclipse 3.1 installation program download 

  Download Address: http://www.eclipse.org/downloads/index.php 

  It should be corresponding version of the JDT, if you download the Eclipse SDK versions own, and if not, with a download page on after some of the JDT download links, download the corresponding documents will be copied into eclipse respectively installation directory the corresponding documents folder. 

  Here we download eclipse-SDK-3.1-win32.zip. 

  5, GEF 3.1 installation program download 

  Download Address: 

  Http://download.eclipse.org/tools/gef/downloads/drops/R-3.1-200507071758/ 

  Index.php 

  Here we download GEF-ALL-3.1.zip. 

  6, Eclipse HTML Editor 1.6.7 installer download 

  Download Address: https: / / sourceforge.jp / projects / amateras / files /? Release_id = 16537 

  # 16537 

  Here we Download: tk.eclipse.plugin.htmleditor_1.6.7.zip. 

  7, StrutsIDE 1.1.7 installer download 

  Download Address: https: / / sourceforge.jp / projects / amateras / files /? Release_id = 16537 # 16537 

  Here we Download: tk.eclipse.plugin.struts_1.1.7.zip. 

  Well, here we all ready for the installation of the package. 

  Second, install and configure the development environment JDK 

  JDK here need only double-click on the exe file installation package, in accordance with tips can be installed.    After the installation is complete, JDK installed under the bin directory folder settings into the path environment variable PATH to.    At the same time, the JRE lib directory of rt.jar packages installed into the environment variable to the classpath. 

  Here we JDK installed on the default installation path C: \ Program Files \ Java \ jdk1.5.0_02 under.    Here is not to say, the Internet can search many JDK installation configuration articles. 

  Third, the installation tomcat server 

  Tomcat need only double-click on the exe file installation packages, and can be installed in accordance with the tips, here we install directory to D: \ Tomcat5.5, the administrator password is set to 12345678. 

  4, installation Eclipse development tools 

  Need only to eclipse-SDK-3.1-win32.zip install decompression, and then inside the eclipse folder shear to the directory to be placed, where we have installed to eclipse the D: \ eclipse directory. 

  Double-click the installation directory eclipse.exe documents, you will start eclipse.    Middle will ask the default working directory, you can according to their default settings, you can also set their own working directory, here set to E: \ workspace directory.    Select Use this as the default and do not ask again options after this start will not be asked to. 

  Eclipse the success of this installation. 

  5, plug-in installed tomcatPlugin 

  Installation is very simple, we have to extract the downloaded installation package tomcatPluginV31beta.zip will extract the com.sysdeo.eclipse.tomcat_3.1.0.beta folder copy to the D: \ eclipse \ plugins directory can be.    We turn off the eclipse has been opened, re-opened, OK, we are now found on the toolbar more than a few Tomcat icon is the tomcat start, stop and restart button.    Eclipse the open window / preferences, we have trees on the left can also be found a tomcat. 

  Click tomcat items, we have chosen the right version 5.x version, and then set tomcat home to the D: \ Tomcat5.5, Contexts directory to D: \ Tomcat5.5 \ conf \ Catalina \ localhost.    Completion of this tomcat plugin installed. 

  6, installation GEF Plugin 

  Similarly, the GEF-ALL-3.1.zip decompress, and then copy decompression after the eclipse directory of the three folders to the D: \ eclipse directory covering all existing folder. 

  Well, this GEF installation is complete. 

  8, creating a test project 

  If you have completed all the above steps can now be restarted eclipse, the newly installed plug-in force, officially developed. 

  1, the use of Sysdeo Tomcat Plugin create tomcat works: 

  File-> new-> others, open new Wizard dialog box, a tree found in java-> tomcat projects, selected, click the next button.    Enter in the projects name textweb, select Use default, click next.    The next Talk to maintain the default settings, click finished.    At this time, we have the package explorer eclipse will be seen in the new project testweb to create complete. 

  2, by adding struts framework 

  File-> new-> others, open new Wizard dialog box, find Amateras-> Struts-> Add Struts Support, select next button click. 

  Keep the default settings, click the Finish button.    Then, in the package explorer eclipse will be seen in the increase in a lot of struts of the library in the WEB-INF also increased under a lot of struts configuration files.    In this project we have joined the Struts framework. 

  3, edit struts-config.xml file 

  In the WEB-INF folder can be found, right-click menu options open with-> Amateras XML Editer can directly edit the xml text, select open with-> struts-config.xml editor in the graphics mode of documents edit. 

  On the right side click on the outline of the struts objects can be added into a new object.    Here, we note here is a more convenient struts-config.xml file editor, we will be behind the development of a simple small procedures. 

  4, a new page index.jsp 

  File-> new-> others, open new Wizard dialog box, find Amateras-> JSP File, click the next button, FileName to index.jsp, click Finish.    Then open index.jsp document for editing, as follows: 

  <% @ Page pageEncoding = "GBK" contentType = "text / html; gb2312 charset ="%> <html> <head> <meta http-equiv = "Content-Type" content = "text / html; charset = gb2312" /> <title> </ title> </ head> <body> <form name="form1" method="post" action="/testweb/logincheck.do"> <table width = "300" border = "0 "cellspacing =" 0 "cellpadding =" 0 "> <tr align="center"> <td colspan="2"> user login information </ td> </ tr> <tr> <td> user name </ td > <td> <input name="username" type="text" id="username"size="12"> user </ td> </ tr> <tr> <td> user passwords </ td> <td > <input name="password" type="text" id="password" size="12"> 123456 </ td> </ tr> <tr align="center"> <td colspan="2"> < input type = "submit" name = "Submit" value = "submit"> </ td> </ tr> </ table> </ form> </ body> </ html> 

  5, create data objects form 

  Open File-> new-> package dialog box, enter com.is.form name, and click Finish button.    Package Explorer in the right of the tree to find just the creation package, right-click com.is.form package, the new menu-> others, find Amateras-> struts-> Struts Action Form, click next, in the name in the dialog box LoginForm input column, click Finish button. 

  Edit the contents of LoginForm categories: 

  Package com.is.form; import org.apache.struts.action.ActionForm; public class LoginForm extends ActionForm (private static final long serialVersionUID = 1L; private String username = ""; private String password = "";/*** @ return Returns the password .* / public String getPassword () (return password;) / *** @ param password The password to set .* / public void setPassword (String password) (password = ;}/** this.password * @ return Returns the username .* / public String getUsername () (return username ;}/*** @ param username The username to set .* / public void setUsername (String username) (username = this.username;)) 

  Note that the two properties were jsp our counterparts in the form of the name of the two input controls, why do so, can look at the struts with the help of documents, I do not detail, also finished form another category attributes, get and set methods can eclipse the source of commands to automatically generate, in the pop-up menu, no detail, to check information on the Internet bar, the use of the eclipse there are many documents. 

  7, plug-in installed Eclipse HTML Editor 

  Decompress tk.eclipse.plugin.htmleditor_1.6.7.zip packets, and then copy plugins directory to D: \ eclipse directory covering the original document folder.    Eclipse HTML Editor plug-in this installation is complete. 

  8, plug-ins installed StrutsIDE 

  Decompress tk.eclipse.plugin.struts_1.1.7.zip packets, and then copy plugins directory to D: \ eclipse directory covering the original document folder. 

  Well, here StrutsIDE plug-in installed. 

  6, objects to create action 

  The same process to create the same form, we are only a com.is.action new package, the same process, opened new wizard, but choose Struts Action, create LoginAction.java type, default value of the election.    We edit LoginAction as follows: 

  Package com.is.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org. apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.is.form.LoginForm; public class LoginAction extends Action (private static final long serialVersionUID = 1L; public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception (/ / this line is here for when theinput page is upload-utf8.jsp, / / it sets the correct characterencoding for the response String encoding = request.getCharacterEncoding (); if (( encoding! = null) & & (encoding.equalsIgnoreCase ( "GB2312 "))){ response.setContentType (" text / html; charset = GB2312 ");) else (response.setContentType (" text / html; charset = GBK ") ;) try (if (form instanceof LoginForm) (LoginForm theForm = (LoginForm) form; if (theForm.getUsername (). equals ( "user") & & theForm.getPassword (). equals ( "123456")) (return new ActionForward ( "/ welcome.do? type = true");) else (return new ActionForward ( "/ welcome.do? type = false");))) catch (Exception e) () / / this shouldn't happen in this example return null;)) 

  Attention here is the direct use of ActionForward to, and you can also provide the blank struts routines struts-blank.war practices in turn, can be compared to the harvest. 

  7, pages created successful login 

  Index.jsp with the creation of the same pages, we create welcome.jsp page, use the default settings.    And edit its content as follows: 

  <% @ Page pageEncoding = "GBK" contentType = "text / html; GBK charset ="%> <html> <head> <meta http-equiv = "Content-Type" content = "text / html; charset = GBK" /> <title> </ title> </ head> <body> <% String type = request.getParameter ( "type"); if (type! = null & type.equals ( "true")) (out.print ( " welcome to you! ");) else (out.print (" Sorry, you enter the user name or password wrong! ");)%> </ body> </ html> 

  8, the increase in Struts-config.xml configuration 

  Add formbean configuration, 
  And labelling between Accession: 

  <form-bean Name="loginForm" type="com.is.form.LoginForm"/> 

  Add jsp document mapping,    And labelling between Accession: 

  <action Path="/index" forward="/index.jsp"/> <action path="/welcome" forward="/welcome.jsp"/> 

  Add action document mapping,    And labelling between Accession: 

  Path = "/ logincheck" type = "com.is.action.LoginAction" name = "loginForm" scope = "request" validate = "true" /> 

  After the revised struts-config.xml form along the following lines: 

  <? Xml version = "1.0"> <! DOCTYPE struts-config PUBLIC "- / / Apache Software Foundation / / DTD Struts Configuration 1.2 / / EN" "http://struts.apache.org/dtds/struts-config_1_2 . dtd "> <struts-config> <data-sources> </ data sources-> <form-beans> <form-bean name="loginForm" type="com.is.form.LoginForm"/> </ form - beans> <global-exceptions> </ global-exceptions> <global-forwards> </ global-forwards> <action-mappings> <action path="/index" forward="/index.jsp"/> <action path = "/ welcome" forward = "/ welcome.jsp" /> <action path = "/ logincheck" type = "com.is.action.LoginAction" name = "loginForm" scope = "request" validate = "true" /> </ action-mappings> <controller processorClass= "org.apache.struts.tiles.TilesRequestProcessor"/> <message-resources parameter="MessageResources"/> <plug-in className = "org.apache.struts.tiles . TilesPlugin "> <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/> <set-property property="moduleAware" value="true"/> </ plug - in> <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property = "pathnames" value = "/ WEB-INF/validator-rules.xml, / WEB-INF/validation . xml "/> </ plug-in> </ struts-config> 

  We can run this test procedure. 

  9, testing procedures 

  Right-click testweb project root directory, click on the menu Tomcate project-> update context definition, the project will be deployed into the tomcat, after the success will be prompted to operate successfully. 

  Click on the menu bar icon Tomcat start tomcat, and then enter the address bar in IE http://localhost:8080/testweb/index.do, we will see index.jsp content pages. 

Untreated "System.Data.SqlClient.SqlException" type anomaly appeared in system.data.dll.

  Untreated "System.Data.SqlClient.SqlException" type anomaly appeared in system.data.dll. 

  Other information: system errors. 
  Laws relating to a SQL database called Real-Time (JIT) debugging this dialog rather than the detailed information, 
  Please refer to the end of this news. 

  The following abnormal The following text 
  System.Data.SqlClient.SqlException: be prepared statement '(@ ID varchar (10), @ name nvarchar (50), @ date of birth datetime, @ gender varchar (10)' @ parameters need salary income, but did not provide the parameters. 
  At System.Data.Common.DbDataAdapter.Update (DataRow [] dataRows, DataTableMapping tableMapping) 
  At System.Data.Common.DbDataAdapter.Update (DataSet dataSet, String srcTable) 
  At WindowsApplication4.Form1.button2_Click (Object sender, EventArgs e) in c: \ documents and settings \ administrator \ my documents \ visual studio projects \ datagridwindowsapplication \ windowsapplication4 \ form1.cs: line 272 
  At System.Windows.Forms.Control.OnClick (EventArgs e) 
  At System.Windows.Forms.Button.OnClick (EventArgs e) 
  At System.Windows.Forms.Button.OnMouseUp (MouseEventArgs mevent) 
  At System.Windows.Forms.Control.WmMouseUp (Message & m, MouseButtons button, Int32 clicks) 
  At System.Windows.Forms.Control.WndProc (Message & m) 
  At System.Windows.Forms.ButtonBase.WndProc (Message & m) 
  At System.Windows.Forms.Button.WndProc (Message & m) 
  At System.Windows.Forms.ControlNativeWindow.OnMessage (Message & m) 
  At System.Windows.Forms.ControlNativeWindow.WndProc (Message & m) 
  At System.Windows.Forms.NativeWindow.Callback (IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 


  The following have been added-The following procedures 
  Mscorlib 
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/microsoft.net/framework/v1.1.4322/mscorlib.dll 
—————————————-
WindowsApplication4
  Set procedures version: 1.0.1803.25611 
  Win32 version: 1.0.1803.25611 
  Basic code: file: / / / C: / Documents% 20and% 20Settings/Administrator/My% 20Documents/Visual% 20Studio% 20Projects/DataGridWindowsApplication/WindowsApplication4/bin/Debug/WindowsApplication4.exe 
—————————————-
System.Windows.Forms
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll 
—————————————-
System
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll 
—————————————-
System.Drawing
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll 
—————————————-
System.Data
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/assembly/gac/system.data/1.0.5000.0__b77a5c561934e089/system.data.dll 
—————————————-
System.Xml
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll 
—————————————-
  Mscorlib.resources 
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/assembly/gac/mscorlib.resources/1.0.5000.0_zh-chs_b77a5c561934e089/mscorlib.resources.dll 
—————————————-
System.Windows.Forms.resources
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/assembly/gac/system.windows.forms.resources/1.0.5000.0_zh-chs_b77a5c561934e089/system.windows.forms.resources.dll 
—————————————-
System.EnterpriseServices
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/assembly/gac/system.enterpriseservices/1.0.5000.0__b03f5f7f11d50a3a/system.enterpriseservices.dll 
—————————————-
System.Data.resources
  Set procedures version: 1.0.5000.0 
  Win32 version: 1.1.4322.573 
  Basic code: file: / / / c: / windows/assembly/gac/system.data.resources/1.0.5000.0_zh-chs_b77a5c561934e089/system.data.resources.dll 
—————————————-

  The following JIT debugging ************************************************ 
  Computer configuration file (machine.config) 
  System.windows.forms section must be set jitDebugging value. 
  Also compiled application procedures must be enabled \ r \ n debugging.    \ R \ n \ r \ n such as: \ r \ n \ r \ n <configuration> \ r \ n <system.windows.forms jitDebugging="true" /> \ r \ n </ configuration> \ r \ n \ r \ n opening JIT debugging, any untreated abnormal \ r \ n will be sent to this computer registered JIT debugger, \ r \ n rather than deal with this dialog box.    \ R \ n 

A java achieve the web calendar

  I believe we have seen a lot of blog sites are some of this month's calendar functions can choose blog above the day to see the author of the diary that day!    There are many ways to achieve this calendar functions can be used javascript, and can also use the web language support to write, for example, asp, jsp support.    Below we came to www.seerlog.net this site (that is, I you), the realization of the calendar module functions as an example to explain the use of java achieve this with the combination of DHTML calendar. 

  An analysis module composition, function 
  The calendar module shows that the main features include a calendar month, a special day, a special day of the blog and show support link to the blog on the day. 
  Functional Analysis of clear, we look at the specific features of this design: First DayStatus sure there is a category used to describe the day whether there is a blog, it is the day of Show.    Other categories also need to generate a DateUtil all DayStatus month target array.    It also needs a haveBlogDay, haveBlogMonth object to preserve owned blog date. 

  Second, prior knowledge 
  1. Jdk1.4 start from the sun provides a java.util.Calendar abstract class, to replace some of the functions of Date and the date to provide more powerful processing capability.    Let us first look at this category (See jdk specific API documentation) 

  Calendar is an abstract base class for a Date object and as a YEAR, MONTH, DAY, HOUR fields such as integer conversion between sets.    (Date object to a representative of the accuracy of time to achieve specific examples of milliseconds. Information on the Date category See java.util.Date.) 

  Calendar sub-categories according to a specific calendar system explain a Date.    Calendar JDK provides a specific sub-categories: GregorianCalendar.    Subclass of the future will represent most of the world's regions of the various types of the lunar calendar. 

  Sensitive with the other country categories, Calendar provides a method getInstance category to obtain the types of a common object.    Calendar of GregorianCalendar getInstance method returns an object, the object's time domain from the current date and time initialization: Calendar rightNow = Calendar.getInstance (); 

  Calendar object to produce the calendar for specific language and style formatting for achieving the time _ the value of all time domain.    (For example, the Japanese - Gregorian calendar, and Japanese - the traditional calendar). 

  When calculated from the time domain Date, may be two situations: either not enough information calculated Date (for example, but only, and does not) or contradictory information (such as "Tuesday, July 15, 1996" — In fact, on July 15, 1996 Monday). 

  Do not have enough information.    Will use the default calendar lack of information specified domain.    This will vary according to different calendars; in the Gregorian calendar, Victoria is the default values starting time: for example, YEAR = 1970, MONTH = JANUARY, DATE = 1, and so on. 

  Conflicting information.    If there is a conflict of jurisdiction, the calendar will be the last set of reference values domain.    For example, when determining day, the calendar will refer to the combination of one of the following domain.    Will be used by the recently set up a single domain identified by the recent combination.    DAY_OF_MONTH MONTH MONTH + + + WEEK_OF_MONTH DAY_OF_WEEK_IN_MONTH DAY_OF_WEEK MONTH + + + WEEK_OF_YEAR DAY_OF_WEEK DAY_OF_YEAR DAY_OF_WEEK time for the day: HOUR_OF_DAY AM_PM + HOUR 

  NOTE: For non-Gregorian calendar in order to ensure no ambiguity, may require different domains.    For example, on the calendar of the Arab universe complete specification is sometimes necessary, on the date in mid-January and the date of the week. 

  NOTE: For some special time of the explanation may be some ambiguity, which can be resolved by the following methods: 

  1.   24:00:00 "is" the next day.    Namely, at 23:59 on November 31, 1969 <January 1, 1970 24:00 <January 1, 1970 24:01:00. 
  2.   Despite the history of inaccurate, but also to the midnight "AM", belonging to noon, "PM", on the same day, 12:00 am (midnight) <12:01 am and 12:00 pm (noon) <12:01 pm. 

  Date or time format string is not part of the definition of the calendar, because in the operation, they must be able to modify or rewrite by the user.    Java.text.DateFormat use formatted date. 

  Calendar for the domain of a "rolling" provides an API, domain can be a plus or minus one, but a rolling cycle.    For example, the date "September 12, 1996" The result is a rolling upward, "October 12, 1996." 

  Calendar also will be designated (with symbols) added to the amount of time specified time domain provides a date calculation functions.    For example, the date "September 12, 1996" by five days by the "September 7, 1996." 

  2.java.text.DateFormat category (See jdk specific API documentation) 

  DateFormat the date / time format of a sub-class of abstract classes, these types of language-based approach to formatting and analysis date or time.    Date / Time-type format, such as SimpleDateFormat, allowing formatted (ie date -> text), analysis (text -> date) and standardization.    Date object by a date, or use the GMT at 0:00:00 on January 1, 1970 from a few milliseconds said. 

  DateFormat to obtain based on the default or to the language environment and formatting style of the default date / time formatting procedures provide many types of methods.    FULL including formatting style, LONG, MEDIUM and SHORT.    The methodology provides a more detailed explanation and examples of the use of these styles. 

  DateFormat help formatting and analysis of the date of any language environment.    Can be independent of the code for the language environment, the agreement weeks, or even independent of the calendar format: lunar and solar. 

  Locale to the date of the current format, use the following methods of static factory: myString = DateFormat.getDateInstance (). Format (myDate); 

  If the number of numerical format was used several times after the format it will be more efficient, such systems would not have to repeatedly fetch on the local language of the agreement for national information.    DateFormat df = DateFormat.getDateInstance (); for (int i = 0; i <)?);?; + Output.println (df.format (mydate [i]) (i + +)> 

  In order to a different format Numerical Locale, calling getDateInstance () specified.    DateFormat df = DateFormat.getDateInstance (Locale.FRANCE); 

  DateFormat also can be used to analyse.    MyDate = df.parse (myString); 

  GetDate use of the country was generally date format.    Also there are other methods available static factory.    GetTime use from the State general time format.    Use getDateTime get a date and time format.    Methods to these factories can be imported different options control the length of the results from the LONG SHORT to MEDIUM to FULL.    The results depend on the precise language environment, but usually: 

  •   SHORT complete figures, for example, or 3:30 pm 12.13.52 
  •   MEDIUM longer, for example, Jan 12, 1952 
  •   LONG longer, such as the January 12, 1952 or 3:30:32 pm 
  •   FULL all designated, for example, Tuesday, April 12, 1952 AD or 3:30:42 pm PST. 

  Time zone can be set to desired format.    If you want to further control the formatting or analysis, (or want to give users more control), may try to get from the factory method for SimpleDateFormat DateFormat deformation.    This will apply to most countries only need to put it in a try block to prevent the event of an accident situation. 

  Can also call FieldPosition ParsePosition and different forms of analysis and formatting method, which will allow: 

  •   Sequencing analysis of the string. 
  •   Adjust any particular domain, or when options on the screen to identify his position. 


  Third, let us achieve this function it hands 

  1. First to achieve haveBlogDay, haveBlogMonth object, the two are actually a HashSet.    Because we will begin to make its data access, in a ServletContextListener category to achieve access. 

  HashSet haveBlogDay; 
  HashSet haveBlogMonth; 

  Try ( 
  Session session = Hi.getSession (); 
  Transaction tx = session.beginTransaction (); 

  / / Initialization haveBlogDay 
  String time_sql = "select topic.submitTime from Topic as topic"; 
  List timeList = session.find (time_sql); 
  For (int i = 0; i <timeList.size (); i + +) 
  ( 
  String tem = (String) timeList.get (i); 
  TimeList.set (i, TextUtil.subString (tem, 10)); 
  ) 
  HaveBlogDay = new HashSet (timeList); 
  Context.setAttribute ( "haveBlogDay" haveBlogDay); 
  Log.info ( "haveBlogDay app has been deposited"); 

  / / Initialization haveBlogMonth 
  For (int i = 0; i <timeList.size (); i + +) 
  ( 
  String tem = (String) timeList.get (i); 
  TimeList.set (i, TextUtil.subString (tem, 7)); 
  ) 
  HaveBlogMonth = new HashSet (timeList); 
  Context.setAttribute ( "haveBlogMonth" haveBlogMonth); 
  Log.info ( "haveBlogMonth app has been deposited"); 


  Above hibernate used to obtain data, the data used here HashSet to ensure repeatability not the only date. 

  2.DayStatus coding design 

  (Public class DayStatus 

  Private boolean have_blog; 

  Private String day; 

  Public DayStatus (int t) ( 
  If (t == 0) ( 
  This.day = ""; 
  This.have_blog = false; 
  ) 
  Else ( 
  This.day = String.valueOf (t); 
  This.have_blog = false; 
  ) 
  ) 

  DayStatus () () 

  Public String getDay () ( 
  Return this.day; 
  ) 

  Public String getFullDay () ( 

  Date now = new Date (); 
  String today = ""; 
  SimpleDateFormat df = new SimpleDateFormat ( "yyyy.MM."); 
  String nowtime = df.format (now). ToString (); 

  If (! Day.equals ( "")) ( 
  If (Integer.parseInt (day) <10) (today nowtime + = "0" + day;) 
  Else (today nowtime + = day;) 
  ) 
  Return today; 
  ) 

  Public boolean haveBlog (HashSet hs) ( 

  Date now = new Date (); 
  String today = ""; 
  SimpleDateFormat df = new SimpleDateFormat ( "yyyy.MM."); 
  String nowtime = df.format (now). ToString (); 

  If (! Day.equals ( "")) ( 
  If (Integer.parseInt (day) <10) (today nowtime + = "0" + day;) 
  Else (today nowtime + = day;) 
  ) 
  Return hs.contains (today); 
  ) 

  Public boolean isToday () ( 
  Date now = new Date (); 
  SimpleDateFormat df = new SimpleDateFormat ( "dd"); 
  String nowtime = df.format (now). ToString (); 

  If (this.day.equals (nowtime)) return true; 
  Else return false; 
  ) 
  ) 

  3.DateUtil coding design is first necessary to define several variables category 

  Private static DayStatus arr [] [] = new DayStatus [6] [7]; 
  Private static int month_count; / / number of days a month 



  Then the definition of getCalendar (): 

  Public DayStatus getCalendar [] [] (int year, int month) ( 

  Calendar ca = new GregorianCalendar (year, month, 1); 

  Int before ca.get = (Calendar.DAY_OF_WEEK) / / by calendar days before the blank 

  Ca.roll (Calendar.MONTH, true); / / one month after rolling 
  Int next_before = ca.get (Calendar.DAY_OF_WEEK); 

  Int after; 
  If (next_before == 1) (after = 7;) 
  Else (after = next_before-1;) / / get the current time 


  / * Get on the number of days, given the leap year February * / 
  If (before <= after) ( 
  Int temp = after-before +1; 
  If (temp <7) (month_count +28 = temp; 
  ) 
  Else (month_count = 28;) 
  ) 
  Else ( 
  Int temp = 8 +-before after; 
  If (temp <7) (month_count +28 = temp; 
  ) 
  Else (month_count = 28;) 
  ) 

  / / System.out.println ( "on the number of days =" + month_count); / / check on the number of days 

  / / Start assignment 

  Int temp_day = 9-before; / / Start the second line of the date of 

  / / System.out.println ( "before =" + before); / / test 
  / / System.out.println ( "after =" + after); 
  / / The first line of treatment 
  For (int k = 0; k <before-1, k + +) ( 
  Arr [0] [k] = new DayStatus (0);) / / for space in front of several assignment 


  For (int m = 1; m <9-before; m + +) ( 
  Arr [0] [before-2 + m] = new DayStatus (m); 
  ) 

  / * Check * accurate completion of the first line / 


  / / Next address 
  For (int i = 1; i <6; i + +) ( 
  For (int j = 0; j <7; j + +) ( 
  If (temp_day <= month_count) ( 
  Arr [i] [j] = new DayStatus (temp_day); 
  Temp_day + +; 
  ) 
  Else (arr [i] [j] = new DayStatus (0);) 
  ) 
  ) 


  / * 
  System.out.println ( "check all arrays"); 
  For (int t = 0, t <6; t + +) ( 
  For (int i = 0; i <7; i + +) ( 
  DayStatus d = arr [t] [i]; 
  System.out.println (d.getDay ()); 
  ) 
  ) 
  * / 
  Return arr; / / array calendar 
  ) 

  4. Prospects display web pages 

  <table Width="100%" border="0" cellpadding="0" cellspacing="0" class="calendarBigBorder" id="caltable"> 
<thead>
  <tr Align="center" valign="middle"> 
  <td Class="calendarTd">, </ td> 
  <td Class="calendarTd"> 1 </ td> 
  <td Class="calendarTd"> 2 </ td> 
  <td Class="calendarTd"> 3 </ td> 
  <td Class="calendarTd"> 4 </ td> 
  <td Class="calendarTd"> 5 </ td> 
  <td Class="calendarTd"> 6 </ td> 
  </ Tr> 
  </ Thead> 
  <TBODY Border=1 cellspacing="0" cellpadding="0" ID="calendar" ALIGN=CENTER> 
<%
  HashSet hs = (HashSet) getServletContext (). GetAttribute ( "haveBlogDay"); 
  DayStatus [] [] = thisMonth DateUtil.getThisCalendar (); 
  For (int i = 0; i <6; i + +) ( 
  Out.print ( "<TR style='cursor:hand'>"); 
  For (int j = 0; j <7; j + +) ( 
  ThisMonth DayStatus ds = [i] [j]; 
  If (ds.isToday ()) ( 
%>
  <TD Class="calendarNow" onMouseover="this.className='calendarHover'" onMouseOut="this.className='calendarNow'"> 
  <% = Ds.getDay ()%> 
  </ Td> 
<%
  ) 
  Else ( 
  If (ds.haveBlog (hs)) ( 
%>
  <TD Class="calendarTd" onMouseover="this.className='calendarHover'" onMouseOut="this.className='calendarTd'"> 
  <A href = "/ topic.do? Time = <% = ds.getFullDay ()%>" class =" a "><%= ds.getDay ()%> </ a> 
  </ Td> 
<%
  Else ()%> 
  <TD Class="calendarTd" onMouseover="this.className='calendarHover'" onMouseOut="this.className='calendarTd'"> 
  <% = Ds.getDay ()%> 
  </ Td> 
  <%)) 
  ) 
  Out.print ( "</ tr>"); 
  ) 
%>
  </ Tbody> 
  </ Table> 


  Here are some scripts, it is really difficult to Kane, of course, you can customize labels to eliminate those ugly code, how kind, a Reconstruction! 

  V. GENERAL 
  Read above almost can understand how to achieve it, in fact here can be better designed, which is a badsmell, what can be reconstructed.    For example, this allows DayStatus designed a simple bean, the function will be shifted out.    DayStatus this can be directly used as a VO in the foreground on the display interface. 

  Well, look at the bar can understand, what contact me yujiebo025@hotmail.com 


Easy Java Portlets

  Portlet is generated fragment (compliance with the norms of specific markup language (such as HTML, XML) fragment) Web Component.    Another fragment of a complete document.    This paper introduces the Java Portlet on the Java Specification Request (JSR) 168 standard.    It explains how to use BEAWebLogic Workshop 8.1 Java Portlet SP2 to create, and how will these portlet deployment to BEA WebLogicPortal 8.1Sp2 on.    I will introduce some of the key concepts, such as portals, desktop and portlet, and described in detail multiple portlet window mode and the state.    I will also explain how to use Workshop to design, implementation, configuration and implementation of portlet. 


  JSR 168 defines the JavaPortlet norms.    Portal is a Web application and a portlet polymerization.    Portlet containers running portlet, and manage their life cycle.    JSR168 portlet and the definition of a contract between the portlet containers, it does not define portlet containers with a contract between the portal.    Portal for the Implementation of the portal provider. 

  BEA WebLogic portal BEA WebLogic Portal (8.1 SP2) to support the current version of the different types of portlet: JSP / HTML portlet, JavaPageFlow portlet, Struts portlet and Java portlet, and the future will also support other portlet, such as WebServices for Remote Portlets (WSRP).    We will focus on Java portlet. 

  WebLogic Portal JSR 168 provides a description of the gateway functions, including but not limited to: books and pages portlet organization, multi-channel support and the use of skin and skeleton and shell customization. 

  In order to be able to continue, in the next part, please complete the following: 
  Use WebLogic Domain Configuration Wizard to create a portal domain (such as JSR168PortalDomain). 
  Use WebLogic Workshop to create a domain established by the use of the above gateway applications (such as JSR168PortalApp). 
  Application procedures in the portal to create a Web portal (such as JSR168PortalWebProject). 
  Web portal in the project to create a WebLogic Portal. Portal document (such as JSR168.portal). 
  Start the server examples. 

  Create your first Java Portlet 
  The following steps describe how to create your first JSR 168 portlet. 
  Web portal in the project (such as JSR168PortalWebProject), the use of WebLogic Workshop for portlet (all FirstPortlet) to create a new folder. 
  In the new folder using Wizard through the creation of the corresponding. Portlet creation of a new portlet documents (such as Firstportlet). 
  Choose the portlet types Java Portlet. 
  Heading designated (eg First). 
  Designated definition labels (such as first). 
  Designated class name (such as com.malani.examples.portlets.jsr168.FirstPortlet). 
  Open portal (such as JSR168.portal). 
  The portlet (such as Firstportlet) drop to the portal page (such as JSR168.portal). 
  Run. Portal document to be tested. 

  Your first JSR 168 portlet have successfully run!    However, a wizard behind what? 
  It created a specific WebLogic Workshop and in the WebLogic Portal. Portlet document.    . Portlet document with a specific to the Workshop and WebLogic Portal. Portal lease documents. 
  Creation of a wizard. Java documents (such as com.malani.examples.portlets.jsr168.FirstPortlet.java), which placed in the WEB-INF/src directory. 
  WEB-INF/portlet.xml wizard to create a configuration file, as well as portlet inserted in the document as a single entry.    The portlet entry looks as follows: 

<portlet>
  <description> Description goes here </ description> 
  <portlet-name> First </ portlet-name> 
  <portlet-class> Com.malani.examples.portlets.jsr168.FirstPortlet 
  </ Portlet-class> 
<portlet-info>
  <title> First </ title> 
  </ Portlet-info> 
  </ Portlet> 

  Java Portlet type in the example, the wizard generated PortletJava javax.portlet.GenericPortlet file extension of the category.    GenericPortlet class implements javax.portlet.Portlet interface.    Figure 1 is a Unified Modeling Language (UML) class diagram, described these relations.    Portlet through direct interface to achieve, can prepare a portlet.    However, the creation of portlet GenericPortlet is a more convenient method.    First, we look at the life cycle of portlet, portlet window mode and the state. 


  Figure 1 

  Portlet life cycle in order to successfully create an portlet, you must comply with the portlet lifecycle.    Javax.portlet.Portlet interface definition of the method of the life cycle, the life cycle approach is init (), render (), processAction () and destroy ().    When deployed portlet example, calls init () method.    It used to obtain any required expensive resources (such as background connection), and the implementation of other one-time activities.    When the case was withdrawn portlet deployment, the use destroy () method to the release of these resources. 

  Portlet norms render a clear distinction between the request and action request.    Figure 2 describes the portlet requests and the response of a UML class diagrams.    Portal on the page render the request would lead to the pages of each portlet on call render () method when the user calls on a specific portlet action (usually HTML form submitted), will be called the portlet The processAction () method.    In this way, users switch to the action request processAction () method call and a render () method calls several times. 


  Figure 2 

  Figure 3 shows a sequence diagram shows that call processAction () method results, as well as portlet on the same page follow-up render () method call.    For more information, please refer to dealing with a movement. 


  Figure 3 

  There are two overloaded init () method, a no parameters, there is a javax.portlet.PortletConfig another instance of the class.    NOTE: on the init (PortletConfig) have a special caveat.    Call super.init (aPortletConfig) failure will lead to a NullPointerException.    Contained in the source code examples illustrate the behavior Initportlet (source code can be found in www.sys-con.com/weblogic/source.cfm). 

  Portlet model JSR168 Portlet definition of the three modes: VIEW, EDIT and HELP.    In an example portlet can happen at any time in a portlet model.    Other custom portlet modes (such as configuration, and source) are possible.    VIEW mode is the default mode.    Portlet norms proposed EDIT mode allows the user to customize the portlet portlet example, as well as portlet HELP pattern display on the use of information.    Portlet must support VIEW model, but in the portlet model and the EDIT HELP mode support is optional.    For example, portlet First portlet example EDIT mode and does not support HELP model. 

  JSR168 state definition window three Window Status: NORMAL, MINIMIZED and MAXIMIZED.    Portlet example any time can be a window happens to be the state.    Other custom window state (such as half a page) is also possible.    In NORMAL mode, the screen area of portlet a small part.    Portlet screen sharing with other states.    In MINIMIZED state, the content of portlet been hidden.    MAXIMIZED in the state, portlet content of the majority of the screen area.    Other shared the same page in MAXIMIZED state portlet been hidden.    For example, portlet First examples to support all three window state. 

  GenericPortlet categories you create the most portlet javax.portlet.GenericPortlet category will be extended, rather than directly to javax.portlet.Portlet interface.    GenericPortlet class implements render () method.    If portlet state of the window was minimized, then render () method can not do anything.    If portlet state of the window is not minimized, then render () method installed in portlet.xml specified in the document title, and call doDispatch () method.    According Portlet model doDispatch () method appropriate to call doView (), doEdit () and doHelp () method.    This category because GenericPortlet help achieve render () method, and provide doView (), doEdit () and doHelp () method to cover, GenericPortlet Portlet analog interface more convenient for extension. 

  First portlet consider examples.    FirstPortlet category expanded GenericPortlet, FirstPortlet rewritten doView () method. 

  Public void doView (RenderRequest request, RenderResponse response) 
  Throws PortletException, IOException 
  ( 
  Response.setContentType ( "text / html"); 
  Response.getWriter (). Write ( "<p> Hello World </ p>"); 
  ) 

  NOTE: Call setContentType () method before calling getWriter () method will lead to java.lang.IllegalStateException. 

  Implementation Portlet model VIEW mode is mandatory, but the EDIT and HELP mode is optional.    In order to achieve EDIT HELPportlet model and the need to achieve in the portlet category appropriate doEdit () and doHelp () method.    Please refer to the source code included in the sample (This article's source code can be found in www.sys-con.com/wldj/sourcec.cfm) in the portletMode.    In addition, the following must be portlet.xml configuration models: 

<supports>
  <mime-type> Text / html </ mime-type> 
  <portlet-mode> Edit </ portlet-mode> 
  <portlet-mode> Help </ portlet-mode> 
  </ Supports> 

  NOTE: Laws portlet.xml configuration file, but does not realize portlet in the corresponding category, will lead javax.portlet.PortletException. 

  JSR 168 window to achieve state did not describe prohibited state support of the window method.    However, the realization of the WebLogic Portal on their banned.    To disable portlet window on the state of the support required in the document weblogic-portlet.xml exclude window Status: 

<portlet>
  <portlet-name> State </ portlet-name> 
<supports>
  <mime-type> Text / html </ mime-type> 
  <excluded-window-state> Minimized </ excluded-window-state> 
  <excluded-window-state> Maximized </ excluded-window-state> 
  </ Supports> 
  </ Portlet> 

  Please refer to the source code examples in the portlet State. 

  Includes JavaServer Pages (JSPs) 
  PortletFirst consider the doView () method, the method obtained Writer examples and direct output HTML fragment.    For a variety of reasons (such as Java to achieve logic and HTML view of the performance of Separation), often do not recommend direct output HTML fragment.    The recommended method is to demonstrate the use of JSP view.    Portlet in the way of the implementation of business logic, render parameters and settings include JSP.    In order to contain a specific JSP, should first obtain PortletContext.    From PortletContext example, by calling getRequestDispatcher () method was a PortletRequestDispatcher examples.    By calling the include () method contains JSP.    For example: 

  / / Execute the necessary logic here … 
  PortletRequestDispatcher aDispatcher = 
  GetPortletContext (). GetRequestDispatcher ( 
  "/ IncludePortlet / includeView.jsp" 
);
  ADispatcher.include (aRequest, aResponse); 

  Note: in the implementation render () method, may use only one portlet PortletRequestDispatcher object. 
  Please refer to the source code included in the portletInclude.    JSP pages (such as includeView.jsp) does not contain root HTML tags (eg <html>, and <title> <body "), because these labels provided by the portal framework.    JSP pages contain only show the necessary HTML portlet fragment. 

  Action in dealing with a standard Web application, an HTML form will lead to the implementation of some business logic.    Deal with the results of operations, or as an attribute has been set up in the conversation and request or transmitted or contained to a JSP. 

  In a JSR 168 portlet, a URL HTML form of action should be what?    JSR 168 defines a JSP tag library called portlettaglib.    HTML form of action URL can be used actionURLportlet label generation.    For example (please refer to favoriteColorEdit.jsp): 

  <Form action = "<portlet:actionURL/>" method = "post"> 

  </ Form> 

  Submit the HTML form will lead the call portlet processAction (ActionRequest aRequest, ActionResponseaResponse) method.    As usual, can be the object by calling the request getParameter () method to obtain the form parameters.    NOTE: Calling moves through the submission of the form, but has no portlet processAction () method will lead to javax.portlet.PortletException. 

  ProcessAction () method set up in response target value.    Do not use or ActionResponse ActionRequest object setAttribute () method.    Value will not processAction () transfer to render () method, but in JSP is not used.    Contrary to use ActionResponse object setRenderParameter () method.    These parameters will render all the follow-up request render available, and this is typical of Web application requests very different attributes.    Typical Webapplication request property can be used only for a request.    On the other hand, render request parameters for many follow-up requests can render.    Render parameters can be maintained until the value of the re-implementation of the action Explicit modify or delete. 

  Consider portletFavoriteColor.    It VIEW model shows the color of a user preference, but in EDIT mode changes.    EDIT mode in preference to the color of choice will be called processAction () method.    The method was preferred color request parameters, and is set to render its parameters.    Thus, the preference parameters render the color in all the follow-up will render in the request are available. 

  Presented by the parameters of what is shown in the JSP?    Portlet from the label should be used for the definition of portlet defineObjects labels to target.    The labels enable renderRequest, renderResponse and portletConfigportlet object in the pages available.    RenderRequest parameters by calling the object getParameter () method to display.    Please refer to the source code contained in the example in favoriteColorView.jsp. 

  PortletFavoriteColor also demonstrated the other concepts.    The first one is how to processAction () method used to change the method portlet programming model.    Call ActionResponse object setPortletMode () method to modify portlet model.    The second concept is the use of an HTML link to amend the portlet model.    The portlet links to the tag library from the renderURL label generation.    According to hope that the portlet model designated portletMode the value of the attribute.    Please refer to the source code examples in the category and favoriteColorView.jsp FavoriteColorPortlet pages. 

  Portlet Preferences 
  PortletPreferences (Portlet first option) is the basic portlet configuration data.    A preference is a "name and value" right.    The name of the type is a string, and the type of value is a string or string array.    Portlet Preference unsuitable for storage of arbitrary data.    Portletpreferences portlet containers to provide sustainability.    In WebLogic Portal, the preference of a lasting only in the following two conditions are true only for the role: 
  Portal running on the desktop, rather than DOT portal model. 
  Users already logged. 

  DOT gateway to the desktop and create a model in WebLogicWorkshop. Portal documents, like books, pages and portlet can be towed into等项. Portal document,. Portal documents can run directly from the Workshop.    However, some features, such as the storage preferences, in which DOT gateway mode operation is not used (DOT also known as single mode portal document mode (Single File Mode)). 

  Other models as desktop models.    Create a portal using PortalAdministrator.    In the portal, a desktop been created.    Like books, pages and portlet等项been created and placed in the desktop.    In this mode, certain functions, such as preferences of storage is available (also known as desktop mode mode (Streamed Mode)). 

  In continuation of the discussion prior to the creation of a desktop: 
  Start Portal Administration (for example, http://localhost:7001/JSR168PortalAppAdmin/).    Portal Administration launched a direct approach from the start in the Workshop.    Portal menu choice, selected Portal Administration menu item. 
  Sign-Portal Administration. 
  Creating a new portal (for example, JSR168). 
  In the portal, create a new desktop (d1). 
  Will be added to the desktop LoginPortlet a page. 
  ContactPortlet will be added to the desktop in a single document. 

  Contact portlet Portlet Preferences examples demonstrating Portlet Preferences.    Portlet Preferences can be static or dynamic.    Portlet together with the static preferences in portal.xml specified in the document.    For example, ContactPortlet into contact with a preference-the preferences.    Contact-preference has been the default value specified: 

<portlet-preferences>
<preference>
  <name> Contact-preference </ name> 
  <value> Email </ value> 
  </ Preference> 
  </ Portlet-preferences> 

  Portlet.xml dynamic preferences is not in the pre-defined configuration files.    When running portlet, these preferences are stored and read.    During the operation, a javax.portlet.PortletPreferences interface contains examples of these preferences.    The examples of the object by calling PortletRequest getPreferences () method was.    The value of specific preferences preferences example by calling on the getValue () method to obtain. 

  Call preferences examples setValue () updates the value of a preferences.    However, additional steps need to submit these amendments.    Examples of preferences store () method is called to make a lasting and preferences.    Preferences only processAction () method changes.    If processAction () method does not call store () method, any preferences examples of changes will be discarded.    NOTE: As mentioned earlier, if you are not logged in DOT portal or gateway mode, then call store () method will lead to a run-time anomaly. 

  Servlet in the portlet and there are many similarities between the points.    However, they are also an important distinction.    Portlet in the establishment of norms on standardized servlet.    Portlet containers exist in servlet container.    Like servlet deployment in a Web application, portlet as well.    Servlet and Web applications using portlet.xml configuration files.    Explicit is a servlet life cycle: init (), doGet (), doPost ().    Similarly, a portlet also have significant life-cycle: doView (), doEdit (), processAction ().    Portlet servlet class and the method must be encoded security threads. 

  However, there are also important differences.    Servlet be permitted to include, forward and redirect operation; However portlet include only be permitted to operate.    Servlet can show a full page, but only to the pages portlet fragment.    Portlet a strict definition of the modalities and Window portlet state, which unlike servlet.    Portlet a more formal request to render the request and action request processing, they also have preferences.    Portlet not servlet! 

  CONCLUSION By using a simple wizard and the creation of portlet description, and describes the life cycle of portlet portlet category, as well as realization of the internal working methods, and describes the portlet.xml configuration file and the corresponding weblogic-portlet.xml configuration file structure and semantics.    Of the various concepts, such as portlet window mode and the state, the paper also explained.    This paper demonstrates the use of portlet tag library and portlet in the form handling.    Finally, I described how to use portletpreferences.    This paper introduced the understanding of these concepts and knowledge, you can create and deploy their own powerful portlet on the road forward. 

  Thanks to thank Subbu Allamaraju, Max Cooper, Steve Ditlinger, David Lu, Roshni Malani and Alex Toussaint, they carefully read the article, and provided valuable feedback. 

  References to discuss the article and questions from here: www.bartssandbox.com.    For free membership. 
  Download, read JSR 168: www.jcp.org/en/jsr/detail?id=168 
  WebLogic Portal documents starting point: e-docs.bea.com/wlp/docs81/index.html 
  Workshop Help build the Java Portlet: e-docs.bea.com/workshop/docs81/doc/en/core/index.html 
  WebLogic Portal 8.1 with the development of JSR 168 Portlet: dev2dev.bea.com/products/wlportal81/articles/JSR168.jsp 
  Web Services for Remote Portlets (WSRP) specification: www.oasis-open.org/committees/tc_home.php?wg_abbrev=wsrp 
  Try WSRP: dev2dev.bea.com/codelibrary/code/wsrp_supportkit.jsp 
  Single File Mode and Streamed Rendering Mode: Click here! 
  Portlet norms of the article: 
  — Introduction Portlet norms, Part 1: 
  Www.javaworld.com/javaworld/jw-08-2003/jw-0801-portlet_p.html 
  — Introduction Portlet norms, Part 2: 
  Www.javaworld.com/javaworld/jw-09-2003/jw-0905-portlet2_p.html 
  JSR 168 of the White Paper description: Click here! 
  Java Passion Portlet speech Notes: www.javapassion.com/j2eeadvanced/Portlet4.pdf 

  Source code - Zip files 
  English Original: http://www.sys-con.com/story/?storyid=45565&DE=1 

  About the author 
  PrakashMalani in the structure, design and software development experience.    He has many applications in the field of software development, such as entertainment, finance, retail, medical, communications and interactive television.    He likes to practice and study advanced technology, such as the Java 2 Enterprise Edition (J2EE), the Unified Modeling Language (UML) and eXtensible Markup Language (XML).    He also California State Polytechnic University, Pomona campus, and other agencies teach best practices and design patterns.    He's well-known in the industry publications published many articles, such as JavaWorld and WebLogic Developers Journal.    At present, he is helping to organize Los Angeles BEA Users Group (LABEAUG). 

keep looking »