| Author |
In the same jsp page I want to display data fetched from database
|
shashanka jena
Greenhorn
Joined: Aug 23, 2006
Posts: 10
|
|
Hi, I have a field Employee Id in the jsp page at the top and so many related field to this employee as Employee name,emp salary etc at the bottom of the page. Once I enter a valid employee id and submit the page the related datas from of the employee are fetched from database and displayed in the same page.I am able to display the data in the same page but for the first time when the page is loaded that is before submiting employee id the other fields are displying null. I want to remove those null. Below I am providing some partial code of my jsp page: <html:form action="/inquire" method="post" onsubmit="return validateInquireForm(this);"> <html:errors/> <table border="0" cellpadding="3" cellspacing="3" width="100%"> <tbody> <tr> <td><p align="right"><font class="text">Employee No.</font></td> <td> <html:text property="emp_number"></html:text> <html:submit value="Fetch"></html:submit> </td> </tr> </tbody> </table> <html:javascript formName="InquireForm" /> </html:form> <%--String email=(String) session.getAttribute("email"); --%> <table border="0" cellpadding="3" cellspacing="3" width="100%"> <tbody> <tr> <td><p align="left"><font class="text">E-mail ID:<%=session.getAttribute("email") %></font></td> </tr> <tr> <td><p align="left"><font class="text">Employee Name:<%=session.getAttribute("empname") %></font></td> </tr>
|
Thanks and Regards<br />shashanka Jena
|
 |
Herman Schelti
Ranch Hand
Joined: Jul 17, 2006
Posts: 387
|
|
hi shashanka, try something like <% if (session.getAttribute("email") != null){ %> <tr> <td><p align="left"><font class="text">E-mail ID:<%=session.getAttribute("email") %></font></td> </tr> <% } %> I see you use Struts, you can also use Struts logic tags to do this. Herman
|
 |
shashanka jena
Greenhorn
Joined: Aug 23, 2006
Posts: 10
|
|
Hi Herman , Whatever you suggested me to do I have already done that .By doing as follows <% if (session.getAttribute("email") != null){ %> <tr> <td><p align="left"><font class="text">E-mail ID:<%=session.getAttribute("email") %></font></td> </tr> <% } %> The E-Mail ID: field is not getting displayed since we are checking "email" field is not eqaul to null but for the first time loading of the page "email" field is null so it will not execute the above code and E-mail ID : field will not be displyed.
|
 |
Herman Schelti
Ranch Hand
Joined: Jul 17, 2006
Posts: 387
|
|
hi shashanka, I'm not sure if I understand your last message, but maybe you want this? <tr> <td><p align="left"><font class="text">E-mail ID: <% if (session.getAttribute("email") != null){ %> <%=session.getAttribute("email") %> <% } %> </font></td> </tr> Herman NB: this code is rather dirty, hard to read etc. If this is for production: try to use tags (Struts or JSTL) instead of scriptlets, and use css for layout instead of html-tags like "font".
|
 |
shashanka jena
Greenhorn
Joined: Aug 23, 2006
Posts: 10
|
|
Hi Herman, Thanks for your suggestion.I have already implemented your suggestion and got my output. Regards, Sahshanka
|
 |
 |
|
|
subject: In the same jsp page I want to display data fetched from database
|
|
|