编辑servlet,显示从数据库中选择的dropwdown值

7fyelxc5  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(332)

我想显示选中的dropwdown值,这样管理员就可以编辑表单而不必再次选择值。我尝试了这个代码,但它不会工作,值没有显示选定的值,它需要管理员重新选择,而不是..有任何错误吗?你们谁能建议一些代码或修复我的?

pw.println("<div class=\"form-group\">");
    pw.println("<label class=\"control-label col-lg-2\">Employment Type <span class=\"required\">*</span></label>");
    pw.println("<div class=\"col-lg-10\">");
    pw.println("<select class=\"form-control m-bot15\" name=\"j_empType\" value='"+ j.getJobemptype() +"' required/> \n " +
    "<option value=\"\" selected disabled>Please Select...</option> \n " +
    "<option value=\"Permanent\">Permanent</option> \n " +
    "<option value=\"Contract\">Contract</option> \n " +
    "<option value=\"Temporary\">Temporary</option> \n " +
    "<option value=\"Part Time\">Part Time</option>");
    pw.println("</select>");
    pw.println("</div>");
    pw.println("</div>");
cld4siwp

cld4siwp1#

好了终于明白了哈哈哈

pw.println("<div class=\"form-group\">");
   pw.println("<label class=\"control-label col-lg-2\">Employment Type <span class=\"required\">*</span></label>");
   pw.println("<div class=\"col-lg-10\">");

   if(!"".equalsIgnoreCase(j.getJobemptype()) && j.getJobemptype()!=null){

        if(j.getJobemptype().equalsIgnoreCase("Permanent")){

            pw.println("<select class=\"form-control m-bot15\" name=\"j_empType\" value='"+ j.getJobemptype() +"' required/> \n " +
               "<option value='"+ j.getJobemptype() +"'>"+j.getJobemptype()+"</option>\n " +
               "<option value=\"Contract\">Contract</option> \n " +
               "<option value=\"Temporary\">Temporary</option> \n " +
               "<option value=\"Part Time\">Part Time</option>");
            pw.println("</select>");

        }else if(j.getJobemptype().equalsIgnoreCase("Contract")){

            pw.println("<select class=\"form-control m-bot15\" name=\"j_empType\" value='"+ j.getJobemptype() +"' required/> \n " +
               "<option value='"+ j.getJobemptype() +"'>"+j.getJobemptype()+"</option>\n " +
               "<option value=\"Permanent\">Permanent</option> \n " +
               "<option value=\"Temporary\">Temporary</option> \n " +
               "<option value=\"Part Time\">Part Time</option>");
            pw.println("</select>");
        }else if(j.getJobemptype().equalsIgnoreCase("Temporary")){

            pw.println("<select class=\"form-control m-bot15\" name=\"j_empType\" value='"+ j.getJobemptype() +"' required/> \n " +
               "<option value='"+ j.getJobemptype() +"'>"+j.getJobemptype()+"</option>\n " +
               "<option value=\"Permanent\">Permanent</option> \n " +
               "<option value=\"Contract\">Contract</option> \n " +
               "<option value=\"Part Time\">Part Time</option>");
            pw.println("</select>");

        }else if(j.getJobemptype().equalsIgnoreCase("Part Time")){

                            pw.println("<select class=\"form-control m-bot15\" name=\"j_empType\" value='"+ j.getJobemptype() +"' required/> \n " +
                              "<option value='"+ j.getJobemptype() +"'>"+j.getJobemptype()+"</option>\n " +
                              "<option value=\"Permanent\">Permanent</option> \n " +
                              "<option value=\"Contract\">Contract</option> \n " +
                              "<option value=\"Temporary\">Temporary</option>");
                            pw.println("</select>");

                            }
                              }else {
                                pw.println("<select class=\"form-control m-bot15\" name=\"j_empType\" value='"+ j.getJobemptype() +"' required/> \n " +
                                  "<option value=\"Permanent\">Permanent</option> \n " +
                                  "<option value=\"Contract\">Contract</option> \n " +
                                  "<option value=\"Temporary\">Temporary</option> \n " +
                                  "<option value=\"Part Time\">Part Time</option>");
                                pw.println("</select>");
                                  }
    pw.println("</div>");
    pw.println("</div>");
zqdjd7g9

zqdjd7g92#

我不明白你的代码,因为它是一个有点未格式化和无用的。我想你的意思是:

for(MyEnum e : MyEnum.values()){
      pw.println("<option value=\""+e.name()+"\">"e.name()"</option>");
}

?

相关问题