JSP easy GetParameter

xiaoxiao2021-03-06  82

/ **

* Returns the value of the specified name in a string from the Request object.

*

Returns the default value if the object corresponding to the Name is empty.

* @Param Request HTTPSERVLETREQUEST REQUEST object

* @Param Name string Specify name

* @Param DefVal String Default

* @Return String

* /

Public String getParam (httpservletRequest Request, string name, string defval) {string param = request.getParameter (name); return (param! = null? param: defval);}

/ **

* Returns the value of the specified name from the Request object.

*

Returns the default value if the object corresponding to the Name is empty.

* @Param Request HTTPSERVLETREQUEST REQUEST object

* @Param Name string Specify name

* @Param Defval INT default value

* @Return Int

* /

public int getParam (HttpServletRequest request, String name, int defval) {String param = request.getParameter (name); int value = defval; if (param = null!) {try {value = Integer.parseInt (param);} catch Numberformatexception Ignore) {}} Return Value;

/ **

* Returns the value of the specified name in a string from the Session object.

*

Returns the default value if the object corresponding to the Name is empty.

* @Param session httpsession session object

* @Param Name string Specify name

* @Param DefVal String Default

* @Return String

* /

public String getSessionParam (HttpSession session, String name, String defval) {Object param = session.getAttribute (name); // session.getValue (name); return (param = null (String) param:!? defval);} / **

* Returns the value of the specified name in the session object.

*

Returns the default value if the object corresponding to the Name is empty.

* @Param session httpsession session object

* @Param Name string Specify name

* @Param Defval INT default value

* @Return Int

* /

转载请注明原文地址:https://www.9cbs.com/read-106385.html

New Post(0)