问题
I'm new to Java EE and Struts2.so i need to find out how to configure struts action to get parameters via post? i had this code to get parameters directly from url like this:
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
response.setContentType("application/json;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
JSONObject jsono = new JSONObject();
JSONArray jsona = new JSONArray();
String keyword = request.getParameter("kw");
//do somthing with kw and return response
but now i have a long request that i prefer to get it like a post parameter. what kind of change i must make in this code
回答1:
All parameters are in the body of the post request. Thus you can get them from there, but if you are using Struts2 you can get them from the action context.
Map parameters = ActionContext.getContext().getParameters();
来源:https://stackoverflow.com/questions/29115948/how-to-configure-struts-action-to-get-parameters-via-post