How to configure struts action to get parameters via post?

醉酒当歌 提交于 2019-12-22 14:01:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!