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

时间:2018-06-22 09:15:54

标签: java mysql servlets web-applications drop-down-menu

我想显示所选的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>");

2 个答案:

答案 0 :(得分:0)

我没有收到您的代码,因为它有点未经格式化且无用。 我认为您的意思是:

http://ce.linedict.com/#/cnen/search?query=goodbye

答案 1 :(得分:0)

好,终于明白了哈哈哈

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>");