Partial code annotation in software development

Source: Internet
Author: User

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.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.