通过map给action传参数的问题。

GengWH 2016-07-26 02:53:28
做了一个登陆页面,安卓页面用
Map<String, Object> params = new HashMap<String, Object>();
params.put("userId", username);
params.put("userPassword", password);
传递参数,用户数据接口用的action接受参数。
ActionContext context=ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);

Map<String, String[]> map = request.getParameterMap();
String[] str = (String[])map.get("userId");
String[] str2 = (String[])map.get("userPassword");

死活接受不到userId,userPassword,是咋回事?跪求!
...全文
371 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
网易云捕 2016-07-28
  • 打赏
  • 举报
回复
/** 
     * post方式提交表单(模拟用户登录请求) 
     */  
    public void postForm() {  
        // 创建默认的httpClient实例.    
        CloseableHttpClient httpclient = HttpClients.createDefault();  
        // 创建httppost    
        HttpPost httppost = new HttpPost("http://localhost:8080/myDemo/Ajax/serivceJ.action");  
        // 创建参数队列    
        List<namevaluepair> formparams = new ArrayList<namevaluepair>();  
        formparams.add(new BasicNameValuePair("username", "admin"));  
        formparams.add(new BasicNameValuePair("password", "123456"));  
        UrlEncodedFormEntity uefEntity;  
        try {  
            uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");  
            httppost.setEntity(uefEntity);  
            System.out.println("executing request " + httppost.getURI());  
            CloseableHttpResponse response = httpclient.execute(httppost);  
            try {  
                HttpEntity entity = response.getEntity();  
                if (entity != null) {  
                    System.out.println("--------------------------------------");  
                    System.out.println("Response content: " + EntityUtils.toString(entity, "UTF-8"));  
                    System.out.println("--------------------------------------");  
                }  
            } finally {  
                response.close();  
            }  
        } catch (ClientProtocolException e) {  
            e.printStackTrace();  
        } catch (UnsupportedEncodingException e1) {  
            e1.printStackTrace();  
        } catch (IOException e) {  
            e.printStackTrace();  
        } finally {  
            // 关闭连接,释放资源    
            try {  
                httpclient.close();  
            } catch (IOException e) {  
                e.printStackTrace();  
            }  
        }  
    }  
  
TyroLJS 2016-07-28
  • 打赏
  • 举报
回复
Map<String, Object>是不是这里的Object这个地方的事,你转成Map<String,String[]>能转么,没用过这种传参方式。
GengWH 2016-07-28
  • 打赏
  • 举报
回复
引用 9 楼 crash163 的回复:
这个帖子应该发到web版块去啊... 不懂web。。。 不过按一般排查思路, 首先确定一下login方法到底有没有被调用, 如果没有被调用,是不是配置有问题? 关于url与action的映射,搜索到这篇文章http://my.oschina.net/zhengjian/blog/98291 祝你好运啊
我用的表单提交,都能获取到map里的值,换成安卓的 client.execute(m);就获取不到了,奇怪了。
「已注销」 2016-07-28
  • 打赏
  • 举报
回复
引用 11 楼 GengWH 的回复:
[quote=引用 9 楼 crash163 的回复:] 这个帖子应该发到web版块去啊... 不懂web。。。 不过按一般排查思路, 首先确定一下login方法到底有没有被调用, 如果没有被调用,是不是配置有问题? 关于url与action的映射,搜索到这篇文章http://my.oschina.net/zhengjian/blog/98291 祝你好运啊
我用的表单提交,都能获取到map里的值,换成安卓的 client.execute(m);就获取不到了,奇怪了。[/quote] 那就是android上调用时,代码写的有问题
GengWH 2016-07-27
  • 打赏
  • 举报
回复
引用 5 楼 crash163 的回复:
好吧,上面我写错了!!!

Map<String,String[]> paramMap = request.getParameterMap();

for(Map.Entry<String,String[]> entry:paramMap.entrySet()){
    String key = entry.getKey();
    String[] value = entry.getValue(); 
    System.out.println(key + " : " +  value[0]);
}
这样看有没有输出?
是不是我不能用action接收参数? @Action("/data/login") public String login() throws SystemException, DatabaseException { session.clear(); ActionContext context=ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST); Map<String,String[]> paramMap = request.getParameterMap(); for(Map.Entry<String,String[]> entry:paramMap.entrySet()){ String key = entry.getKey(); String[] value = entry.getValue(); System.out.println(key + " : " + value[0]); } }
网易云捕 2016-07-27
  • 打赏
  • 举报
回复
这个帖子应该发到web版块去啊... 不懂web。。。 不过按一般排查思路, 首先确定一下login方法到底有没有被调用, 如果没有被调用,是不是配置有问题? 关于url与action的映射,搜索到这篇文章http://my.oschina.net/zhengjian/blog/98291 祝你好运啊
GengWH 2016-07-27
  • 打赏
  • 举报
回复
求大神帮助!!
GengWH 2016-07-27
  • 打赏
  • 举报
回复
求大神帮助!!
网易云捕 2016-07-26
  • 打赏
  • 举报
回复
好吧,上面我写错了!!!

Map<String,String[]> paramMap = request.getParameterMap();

for(Map.Entry<String,String[]> entry:paramMap.entrySet()){
    String key = entry.getKey();
    String[] value = entry.getValue(); 
    System.out.println(key + " : " +  value[0]);
}
这样看有没有输出?
GengWH 2016-07-26
  • 打赏
  • 举报
回复
求大神帮助!
GengWH 2016-07-26
  • 打赏
  • 举报
回复
求大神帮助!
GengWH 2016-07-26
  • 打赏
  • 举报
回复
引用 1 楼 crash163 的回复:
Map<String, String[]> map = request.getParameterMap();
String[] str = (String[])map.get("userId");
String[] str2 = (String[])map.get("userPassword");

----------->>>>>>>>>

Map<String, String> map = request.getParameterMap();
String str = (String)map.get("userId");
String str2 = (String)map.get("userPassword");


///

网易云捕 2016-07-26
  • 打赏
  • 举报
回复
Map<String, String[]> map = request.getParameterMap(); String[] str = (String[])map.get("userId"); String[] str2 = (String[])map.get("userPassword"); ----------->>>>>>>>> Map<String, String> map = request.getParameterMap(); String str = (String)map.get("userId"); String str2 = (String)map.get("userPassword"); ///

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧