1

I have a jsp form page where created a dropdown field. Based on one of the value chosen I need to show the upload button option which is in different jsp. I tried the below code. Can someone please assist me what am missing here as the code is not showing any error and not working thou.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
...
<body>

    <div align="center" style="margin-top: 50px;">

        <form action="FirstwebServlet">
            Please enter username: <input type="text" name="username" size="20px"> <br>
            Please enter your password: <input type="text" name="password" size="20px"> <br>


               <br> Please select the option: 
               <select required="required" name="sel">
                 <option value="None">Choose from the list </option>
                 <option value="Report">Report</option>
                 <option value="Template">Template</option>


               </select> <br> 
              <% String sel = request.getParameter("sel");
   if( sel != null  && sel =="Template" ) {%>
       <%@ include file="upload.jsp" %> 

  <%  }
%>
            <input type="submit" value="submit">
        </form>

    </div>

</body>
</html>

I am not seeing any error for this code. But when I select the dropdown value it's not taking to upload field code.

Jozef Chocholacek
  • 2,874
  • 2
  • 20
  • 25
TTT
  • 37
  • 8
  • Is this `FirstwebServlet` name of your current `jsp` page in which you have form,also what happen when you click on submit button ? – Swati Sep 10 '19 at 12:53
  • You have to handle the `change` event of your ` – Jozef Chocholacek Sep 10 '19 at 13:03
  • Long story short: google for `AJAX`. And maybe also for `life cycle of HTML page`. – Jozef Chocholacek Sep 10 '19 at 13:04
  • jstl should work for if else right? am i missing something – TTT Sep 10 '19 at 13:25
  • if someone could guide me how to achieve this would really help. I checked Ajax .. couldnt find much on the requirement. simple snippet would help. – TTT Sep 10 '19 at 14:18
  • @TTT use `onchange` event of jquery and then check there if the value is equal to `Template` if yes use .`append()` to append a upload button in form . You don't need to use ajax for this ,if you need to check only one value ..you can easily do that by `jquery` or `js`. – Swati Sep 10 '19 at 14:44
  • 1
    you are amazing. jquery worked !!! appreciated @Swati – TTT Sep 10 '19 at 15:21

0 Answers0