Jump to content
Sign in to follow this  
Gjob83

Seleccionar item de Lista html consoante var de amb

Recommended Posts

Gjob83

Bom dia,

Tenho uma lista de valores em html, e só quero que fique uma seleccionada consoante o valor de uma determinada variavel de ambiente.

Tenho o seguinte código, mas não funciona:

<td>

<select name="ambiente">

  <option value="dev" <% if(session.getAttribute("sync").equals("dev")||session.getAttribute("username")==null) {%> selected="selected" <%}%> >Dev</option>

  <option value="qa" <% if(session.getAttribute("sync").equals("qa")) {%> selected="selected" <%}%> >Qa</option>

    <option value="prd" <% if(session.getAttribute("sync").equals("prd")) { %> selected="selected" <%}%> >Prd</option>

</select>

</td>

Obtenho o seguinte erro. Alguem me pode ajudar? Obrigado

org.apache.jasper.JasperException: Exception in JSP: /sincronizacao.jsp:38

35: <tr>

36: <td>

37: <select name="ambiente">

38:   <option value="dev" <% if(session.getAttribute("sync").equals("dev")||session.getAttribute("username")==null) {%> selected="selected" <%}%> >Dev</option>

39:    <option value="qa" <% if(session.getAttribute("sync").equals("qa")) {%> selected="selected" <%}%> >Qa</option>

40:    <option value="prd" <% if(session.getAttribute("sync").equals("prd")) { %> selected="selected" <%}%> >Prd</option>

41: </select>

Stacktrace:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.lang.NullPointerException

org.apache.jsp.index_jsp._jspService(index_jsp.java:684)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)

javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


"O que não nos mata, torna-nos mais fortes!"

Share this post


Link to post
Share on other sites
Gjob83

<select name="ambiente">

<% out.println(session.getAttribute("sync")); 

if(session.getAttribute("sync")==null){ %>

  <option value="dev" selected="selected">Dev</option>

  <option value="qa">Qa</option>

    <option value="prd">Prd</option>

  <% } else {%>

  <%  if(session.getAttribute("sync").equals("dev") ){ %>

  <option value="dev" selected="selected">Dev</option>

  <option value="qa" >Qa</option>

    <option value="prd">Prd</option>

  <% } else {%>

  <%  if(session.getAttribute("sync").equals("qa") ){ %>

  <option value="dev" >Dev</option>

  <option value="qa" selected="selected">Qa</option>

    <option value="prd">Prd</option>

  <% } else {%>

  <%  if(session.getAttribute("sync").equals("prd") ){ %>

  <option value="dev" >Dev</option>

  <option value="qa">Qa</option>

    <option value="prd" selected="selected">Prd</option>

  <% } %> <% } %> <% } %><% } %>

</select>


"O que não nos mata, torna-nos mais fortes!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.