• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

In the same jsp page I want to display data fetched from database

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Herman,
Thanks for your suggestion.I have already implemented your suggestion and got my output.

Regards,
Sahshanka
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic