# 3.4 get & getPara series methods

The Controller provides the getPara series of methods to obtain parameters from the request. The getPara series is divided into two types. The first type includes the getPara series of methods where the first parameter is of type String. This series of methods encapsulates the HttpServletRequest.getParameter(String name) method, and they all call HttpServletRequest.getParameter(String name).

The second type includes the getPara series of methods where the first parameter is of type int or has no parameters. This series of methods retrieves the parameter value from urlPara. getParaMap and getParaNames correspond to HttpServletRequest's getParameterMap and getParameterNames, respectively.

Memory trick: The methods where the first parameter is a String will obtain field values from the form or URL parameters. Those with an int as the first parameter or no parameters will get the parameter values from urlPara.

Usage examples of getPara:

Method Call Return Value
getPara("title") Returns the form field "title" parameter value.
getParaToInt("age") Returns the form field "age" parameter value and converts it to int type.
getPara(0) Returns the first value of the URL's urlPara parameter. For example, the request http://localhost/controllerKey/method/v0-v1-v2 will return "v0".
getParaInt(1) Returns the second value of the URL's urlPara parameter and converts it to int type. For example, the request http://localhost/controllerKey/method/2-5-9 will return 5.
getParaInt(2) For the request http://localhost/controllerKey/method/2-5-N8, this will return -8. Note: The letters "N" and "n" both represent a negative sign, which is useful when the urlParaSeparator is "-".
getPara() Returns the entire value of the URL's urlPara parameter. For example, the request http://localhost/controllerKey/method/v0-v1-v2 will return "v0-v1-v2-v3".

Important update in jfinal 3.6: JFinal 3.6 added shorter alternative methods to the getPara and getParaToXxx series of methods. Below are some usage examples:

// Replacing `getPara` with `get`
String title = get("title");
 
// Replacing `getParaToInt` with `getInt`
Integer age = getInt("age");
 
// Replacing `setAttr` with `set`
set("article", article);
1
2
3
4
5
6
7
8

Important update in jfinal 3.5: JFinal 3.5 introduced the getRawData() method, making it easy to retrieve String type data from the HTTP request body, typically in JSON or XML format, such as:

String json = getRawData();
User user = FastJson.getJson().parse(json, User.class);
1
2

In the above code, getRawData() retrieves the String-type JSON data sent from the client. The getRawData() method can be called multiple times in a single request-response interaction without throwing an exception.

Note that when forwarding to another action using forwardAction(...), getRawData() cannot retrieve data. In this case, use setAttr("rawData", getRawData()) to pass the data to the target action being forwarded to, and then in the target action, retrieve it using getAttr("rawData"). This situation is rare.

Last Updated: 9/17/2023, 5:50:29 AM