web development Tips

session sharing mechanism: f5 to refresh the data prior to submitting the request again belong to a different address bar Enter different browser requests to obtain data before the same browser can not get synchronized data 

session logoff: session.invalidate (); // All session fails 
	     session.removeAttribute (xxx); // a failure the session 

cookie: built-in objects need not new but the server will automatically only a new name for the jssionid the cookie 
	obtain the name of the cookie object getNmae () 
	getValue () Gets the value of the cookie object 
	request .getCookies () Gets an array of cookie objects 

get browser Jessionid: request.getCookies () [0] .getValue () and session.getId () as the value of 

virtual path application.getContextPath () of the current project 
application.getRealPath (application. getContextPath ()) of the current absolute path project 

to solve post request distortion: Request.setCharacterEncoding ( "UTF-. 8"); 
		  response.setCharacterEncoding ( "UTF-. 8"); 

four kinds of target range: are set, getAttribute method 
	pagecontext current page valid  
	request with a request to forward valid request can share data, redirect (secondary Demand) can not get the data
	session to change the browser, close the browser invalid
	application throughout the project period runs are valid, including changing browser / close your browser or visit other items will be invalid 
	···· JNDI technology enables close the browser or other program access will effectively · · · · 

JDBC: the DriverManager-jdbd drive 
	connection- connected 
	Statement Connection.createStatement () 
	PreparedStatement Connection.prepareStatement ()) 
	ResultSet return result sets	 
	callablestatement Connection.prepareCall call stored procedures and functions (process, function name) 
	process without return value return value returned by the function is stored in place out 
	examples: xxx = connection.preparecall ( "{call procedure name (?,?,?)}") 
		xxx.setInt (. 1, XX) 
		xxx.setInt (2, XX) 
		xxx.execute () 
		xxx.registeroutparameter (. 3, Types. INTEGER) // set the return type 
		int result = xxx.get (3)

	orecle large text BLOB, CLOB (slightly larger data may also be stored after the operation io path, the path disadvantage by impact) heavy drawbacks, affecting the database memory xxx.setBinarystream (2, inputstream); || the first reader built into the object inputstream xxx.setCharacterstream (2, Reader); 
	MySQL is the TEXT 

JavaBean defined: 1, public class modified, public constructor with no arguments 2, the property is private, and provides a get, set method. 
		Encapsulated data, improving rate of code reuse 

servlet2.5 used to configure routing in web.xml 
	servlet3.0 need not be configured, but before the class of the control layer to add annotations @WebServlet ( "url address") 
	2.5web.xml by load-on-startup disposed whoever performs initialization to determine the number 
	3.0 in @WebServlet (load-on-startup = xx) 

writing difference url: <a href="a/add"> requests to src, webcontent the first find is there a 
	     the web.xml in / root path of the project on behalf of 
	     the jsp / representatives domain + port number portion of 

the life cycle of servlet: 
	load (without intervention, automatic) - initialization method init (executed once) - service (service abstract methods ) - destruction destroy method - unloaded (without intervention, automatically) 

the web.xml set: 
	  the parameters set in the entire web container 
	  <context-param>
          <param-name> XXX </ param-name> 
          XXXX </ param-value> <param-value> 
          </ context-param> 
	  parameters obtained by: using in a servlet where servletContext = super.getServletContext the ServletContext (); 
		String String = servletContext.getInitParameter ( "parameter name"); 
		System.out.println (String); 

	parameter set in the current embodiment the servlet: 
	<servlet> 
   	 <servlet-name> XXX </ servlet-name> 
    	<servlet-class> 
		XXXX 
		< / the servlet-class> 
    	<the init-param> 
     	 <param-name> xxxxx </ param-name> 
      	<param-value> XXXXXXX </ param-value> 
    	</ the init-param> 
   	 <Load-ON-Startup>. 1 </ load-on-startup>
 	 </servlet>
	Parameters obtained manner: string a = super.getInitParameter ( "parameter name") with the servlet;
 
air interface realize the benefits: 
	no class that implements the interface with class inheritance --- --- --- empty class that implements an interface 
	can be an interface the method does not implement the 

servlet obtains out, session, application of the method of 
		the Session the session = (the Session) Request.getSession (); 
		the PrintWriter pWriter response.getWriter = (); 
		file application: the ServletContext S = (the ServletContext) request.getServletContext () ; 
		


acquisition request data stored in the database, check the database stored in the data garbled question:? jdbc: MySQL: // localhost / Article This article was useUnicode to true = = UTF-8 & characterEncoding 

JSP --- ---- the Java class file: Tomcat's work folder 

mysql for paging: 
	mysql starts from 0, oracle, sqlserver beginning from the first 
	start data is assumed from page 10 page 0: select * from stu limit 0,10; 
	general format: select * from table limit (this page -1) * pageSize, pageSize;
oracle tab,: select * from stu where sno > = (n-1) * 10 + 1 and sno <= n * 10; provided that the data is continuous id 
	pseudo-column solution can not be greater than or equal nested query results 
	: Use the pseudo column select s * from stu s order by sno asc; first sort 
	then: SELECT rownum, T * from T (SELECT S * from STU S Order by SnO ASC.) 
		WHERE rownum> = (n--. 1) * 10 + 1 and rownum <= n * 10 ; 
	last: SELECT * from ( 
	. SELECT rownum R & lt, T * from (SELECT S * from STU S Order by SnO ASC) T 
		WHERE rownum> = (n--. 1) * 10 +. 1 and rownum <= n-* 10;) T 
	) WHERE R & lt> = (n--. 1) * 10 +. 1 and R & lt <= n-* 10; 
	optimize performance: SELECT * from ( 
	SELECT rownum R & lt, T * from (SELECT S *. from STU S Order by SnO ASC) T 
		 WHERE rownum <= n-* 10 
	) WHERE R & lt> = (n--. 1) * 10 +. 1; 

SQLServer2005 + tabs: rownum can not be directly used, need to be developed as a pseudo-column: select * from (
	row_num SELECT () over (SnO Order by SnO ASC) R & lt AS, from STU WHERE R & lt * <= n-10 * 
	) R & lt WHERE> = (. 1-n-) 10 + *. 1; 

sqlserver2003 tab: top keyword select top 3 * from stu; query if the first page of data per three

sqlserver2012+分页:offset fetch next only
	select * from stu order by sno offset ( Page 1) * +1 a page size of rows fetch next page size rows only 

paging achieved: the need for five variables (the amount of data COUNT the SELECT (*) from STU; 
			, strips per page user-defined page size 
			, total number of pages, the program automatically calculates the sum% xx == 0 sum / xx :? sum / xx + 1 
			of the current page numbers, user-defined 
			objects in the current page collection) list set of queries 

to get all the form data methods : 
	var Data = $ ( "form") the serialize ();. 

return & return 
	in the try return, before finally executed will result saved, even if modifications are finally also to hold the try value prevail, but if it is reference type, modified attributes will finally prevail after the modification; 
3, if the try / finally return has, finally returned directly in return. 

+ / concat 
	+ may be a string or number and other basic data types, and concat only receive a string. 

+ May be left null, concat to be a null pointer. 

	If the stitching empty string, concat will be slightly faster, both in speed is negligible, if more string splicing is recommended StringBuilder.

Compiled byte code + number from the point of view is the use of StringBuiler to splice, so the line +++ statement will create a StringBuilder, multiple +++ statement to create multiple, so why use StringBuilder recommendations. 

Serialization	 
	If you do not want to serialize a field in front of the field plus transient keywords. 

A response JSON-based API that should contain the following header 
	Content-Type: the Application / json; charset = UTF-8 

set to automatically refresh 
Response.setHeader ( "Refresh", "1000 ; URL = http: // localhost: 8080 / servlet / example.htm "); 

how to implement JSP Servlet or single-threaded mode? 
For JSP pages, page can be set by command. 
<% @ page isThreadSafe = "false "%> 
for Servlet, Servlet can make custom implementation SingleThreadModel identity interface. 
Note: If the JSP or Servlet set to single-threaded mode of operation, will lead each request to create a Servlet examples, this practice will lead to (a lot of memory pressure on the server, but also lead to frequent garbage collection) serious performance problems, so usually I do not do that.

















	

  

Guess you like

Origin www.cnblogs.com/qinyios/p/11125006.html