我有一个原来用PHP写的函数,现在想用java重新写,并实现同样的功能,不会了,请各位高手给予指教。
php代码如下:function formheader($arguments=array()) {               if ($arguments[enctype]){
                   $enctype="enctype=\"$arguments[enctype]\"";
               } else {
                   $enctype="";
               }
               if (!isset($arguments[method])) {
                   $arguments[method] = "post";
               }
               if (!isset($arguments[action])) {
                   $arguments[action] = "_self";
               }               if (!$arguments[colspan]) {
                   $arguments[colspan] = 2;
               }
               echo "<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"4\" class=\"tableoutline\">\n";
               echo "<form action=\"$arguments[action]\" $enctype method=\"$arguments[method]\" name=\"$arguments[name]\" $arguments[extra]>\n";
               if ($arguments[title]!="") {
                   echo "<tr id=\"cat\">
                          <td class=\"tbhead\" align=\"left\" colspan=\"$arguments[colspan]\">
                          <font color=\"#DDBC00\"><b>$arguments[title]</b></font>
                          </td>
                         </tr>\n";
               }      }
php中的数组可以用字符串作为键值,但是java中不行,我应该如何实现?谢谢大家!

解决方案 »

  1.   

    我用了HashMap().有没有更好的解决办法?
    public String formheader(Map formMap){
    String enctype; if(formMap.get("enctype") != null){
    enctype = "enctype=\""+formMap.get("enctype")+"\"";
    }else{
    enctype = "";
    }

    String formheaderString = "<table width=\"100%\" align=\"center\" border=\"0\" cellspacing=\"1\" cellpadding=\"4\" class=\"tableoutline\">\n" +
    "<form action=\"$arguments[action]\" "+enctype+" method=\"$arguments[method]\" name=\"$arguments[name]\" $arguments[extra]>\n";
    return formheaderString;
    }
      

  2.   

    我觉得hashmap就是最好的解决办法了,要么你就自已写值类(就是只有getter和setter)然后调用的时候参数为这个值类
      

  3.   

    key value还是map比较合适
    直接echo感觉不清晰,还是set以后再用类似于jstl在页面取出来吧
    比较合理