When you first get started with software development, read other people's code first. Learn other people's experience! The following are some codes and annotations we have encountered!
@ Parentpackage ("basepackage") // inherits the <package name = "basepackage" extends = "struts-Default">
/** Function: converts an object to a JSON string and returns the response to the foreground. * Conversion reason: the data format used on the page is JSON * generally, we use Struts-JSON-plugin encoding on the server side and net on the client side. SF. JSON-lib decoding * both components use the JSON Protocol */Public void writejson (Object object) {try {string JSON = JSON. tojsonstringwithdateformat (object, "yyyy-mm-dd hh: mm: SS"); servletactioncontext. getresponse (). setcontenttype ("text/html; charset = UTF-8"); servletactioncontext. getresponse (). getwriter (). write (JSON); servletactioncontext. getresponse (). getwriter (). flush (); servletactioncontext. getresponse (). getwriter (). close ();} catch (ioexception e) {e. printstacktrace ();}}
Sysuser is a class that encapsulates many attributes and methods!
Classasfactory <sysuser> C = new classasfactory <sysuser> (sysuser. Class); // generic implementation class
Class classasfactory <t> {// use t x for generic erasure; Public classasfactory (class <t> kind) {try {x = kind. newinstance () ;}catch (exception e) {Throw new runtimeexception (e );}}}Introduction to generic Erasure
Public httpsession getsession () {// This method gets the request's session return servletactioncontext. getrequest (). getsession ();}
Public httpsession getsession (Boolean create ){...}
Httpsession session = request. getsession (ture); If the parameter is set to true, a new session is created if no session exists on the server. If yes, a session is obtained. If the input parameter is false, the session is obtained if any. If no session is created on the server and no new one is created, the return value is null.
The HTTP session interface definition \ public interfacehttpsession is used by the servlet engine to associate the HTTP client with the http session. This association lasts for a specified period of time in multiple external connections and requests. Session is used to maintain the status and identify users by crossing multiple request pages under stateless HTTP protocol. A session can be maintained by cookie or URL rewriting.