473,499 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Retrieve data from Database using struts jsp

lifeisgreat20009
70 New Member
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please give me some idea where I am going wrong ??

I just want to retrieve data from my emp_mstr table and display it using my JSP file...

The table emp_mstr is as follows :-

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE EMP_MSTR(
  2.     EMP_NO VARCHAR(10) PRIMARY KEY, 
  3.     PASSWORD VARCHAR(6),
  4.     BRANCH_NO VARCHAR(10), 
  5.     FNAME VARCHAR(25), 
  6.     MNAME VARCHAR(25), 
  7.     LNAME VARCHAR(25), 
  8.     DEPT VARCHAR(30), 
  9.     DESIG VARCHAR(30), 
  10.     ADDR VARCHAR(50)
  11. );

My JSP file is as follows :-

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  4. <title>corporate bank</title>
  5. <meta name="keywords" content="" />
  6. <meta name="description" content="" />
  7. <link href="../resource/styles.css" rel="stylesheet" type="text/css" media="screen" />
  8. </head>
  9. <body>
  10. <div id="main">
  11. <!-- start header -->
  12. <div id="header">
  13.  <div id="logo">
  14.     <h1>Corporate Bank</h1>
  15.   </div>
  16. <!--Header end -->
  17. <div id="menu">
  18.   <ul>
  19.    <li><a href="#">Home</a></li>
  20.    <li><a href="#">Products</a></li>
  21.    <li><a href="#">Easy loans</a></li>
  22.    <li><a href="#">About us</a></li>
  23.    <li><a href="#">Contact</a></li>   
  24.   </ul>
  25. </div>
  26. </div>
  27.  
  28. <!-- end header -->
  29. <!-- start page -->
  30. <div id="page">
  31.     <!-- start leftbar -->
  32.     <div id="leftbar" class="sidebar">
  33.             <h2>Branch Network</h2>
  34.  
  35.              <div class="back">
  36.  
  37.                 <ul>
  38.                     <li><a href="#">Branches</a></li>
  39.                     <li><a href="#">ATMs</a></li>
  40.                     <li><a href="#">Overseas Branches</a></li>
  41.                     <li><a href="#">Phone banking numbers</a></li>
  42.  
  43.                 </ul>
  44.                 </div><div class="bottom"></div>
  45.                 <h2>General Information</h2>
  46.                 <div class="back">
  47.                 <ul>
  48.                     <li><a href="#">Interest rates on FD</a></li>
  49.                     <li><a href="#">Service charges and fees</a></li>
  50.  
  51.                     <li><a href="#">Download Forms</a></li>
  52.                     <li><a href="#">FAQ's</a></li>
  53.                   </ul>
  54.                 </div>
  55.                 <div class="bottom"></div>
  56.     </div>
  57.  
  58.     <!-- end leftbar -->
  59.     <!-- start content -->
  60.     <div id="content">
  61.         <div class="post">
  62.              <h1 class="title">Employee Details</h1>
  63. <br><br>     <center><table>
  64. <tr>
  65. <td>
  66. <div>Employee No.</div>
  67. </td>
  68. <td><bean:write name="employeeDetailForm" property="empNo"/></td>
  69. </tr><tr></tr><tr></tr><tr></tr>
  70. <tr valign="top">
  71. <td>
  72. <div>Branch No.</div>
  73. </td>
  74. <td><bean:write name="employeeDetailForm" property="branchNo"/></td>
  75. </tr><tr></tr><tr></tr><tr></tr>
  76. <tr valign="top">
  77. <td>
  78. <div>First Name</div>
  79. </td>
  80. <td><bean:write name="employeeDetailForm" property="fName"/></td>
  81. </tr><tr></tr><tr></tr><tr></tr>
  82. <tr valign="top">
  83. <td>
  84. <div>Middle Name</div>
  85. </td>
  86. <td><bean:write name="employeeDetailForm" property="mName"/></td>
  87. </tr><tr></tr><tr></tr><tr></tr>
  88. <tr valign="top">
  89. <td>
  90. <div>Last Name</div>
  91. </td>
  92. <td><bean:write name="employeeDetailForm" property="lName"/></td>
  93. </tr><tr></tr><tr></tr><tr></tr>
  94. <tr valign="top">
  95. <td>
  96. <div>Department</div>
  97. </td>
  98. <td><bean:write name="employeeDetailForm" property="dept"/></td>
  99. </tr><tr></tr><tr></tr><tr></tr>
  100. <tr valign="top">
  101. <td>
  102.  
  103. <div>Designation</div>
  104. </td>
  105. <td><bean:write name="employeeDetailForm" property="desig"/></td>
  106. </tr><tr></tr><tr></tr><tr></tr>
  107.  
  108. <tr valign="top">
  109. <td>
  110.  
  111. <div>Address</div>
  112. </td>
  113. <td><bean:write name="employeeDetailForm" property="address"/></td>
  114. </tr><tr></tr><tr></tr><tr></tr>
  115.  
  116.  
  117. <tr valign="top">
  118. <td>
  119. </tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr>
  120. <tr></tr><tr></tr><tr></tr><tr></tr>
  121. <tr><td colspan=2>
  122. <center><a href="search employee.html">Search Employee</a></center>
  123. </td>
  124. </tr>
  125.  
  126. <tr></tr><tr></tr><tr></tr><tr></tr>
  127. <tr><td colspan=2>
  128. <center><a href="search customer.html">Search Customer</a></center>
  129. </td>
  130. </tr>
  131.  
  132. <tr></tr><tr></tr><tr></tr><tr></tr>
  133. <tr><td colspan=2>
  134. <center><a href="activate saving account.html">Activate Account</a></center>
  135. </td>
  136. </tr>
  137.  
  138. <tr></tr><tr></tr><tr></tr><tr></tr>
  139. <tr><td colspan=2>
  140. <center><a href="new employee.html">New Employee</a></center>
  141. </td>
  142. </tr>
  143.     </table></center>
  144. <br><br>
  145.         </div>
  146.     </div>
  147.     <!-- end content -->
  148.     <!-- start rightbar -->
  149.     <div id="rightbar" class="sidebar">                
  150.                 <h2>Login</h2>
  151.                  <div class="back">
  152.                 <form action="">
  153.     <center><table>
  154.     <tr ><td color=#000000>You have logged in as:</td></tr>
  155.     <tr><td><center>.......</center></td>
  156.     </tr>
  157.   <tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr>
  158. <tr></tr><tr></tr><tr></tr><tr></tr>  
  159.     <tr><td><center><a href="#">logout<a><center></td></tr>
  160. <tr></tr><tr></tr>    </table></center>
  161.   </form>
  162.  
  163.                 </div><div class="bottom"></div>
  164.                 <h2>News</h2>
  165.                  <div class="back">
  166.                 <ul>
  167.                     <li><a href="#">Aliquam libero</a></li>
  168.                     <li><a href="#">Consectetuer adipiscing elit</a></li>
  169.                     <li><a href="#">Urnanet non molestie semper</a></li>
  170.                     <li><a href="#">Proin gravida orci porttitor</a></li>
  171.                 </ul>
  172.                 </div><div class="bottom"></div>
  173.     </div>
  174.     <!-- end rightbar -->
  175.     <div style="clear: both;">&nbsp;</div>
  176. </div>
  177. <!-- end page -->
  178.  <div id="footer">
  179.    <p>Copyright &copy; 2009. <a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a> | <a href="#" title="This page validates as XHTML 1.0 Transitional"><abbr title="eXtensible HyperText Markup Language">XHTML</abbr></a> | <a href="#" title="This page validates as CSS"><abbr title="Cascading Style Sheets">CSS</abbr></a></p> 
  180.     <p>Design by <a href="#" title="CORPORATE BANK">Corporate Bank</a></p>
  181.  
  182. </div>
  183. </html>
  184.  
employeeDetailForm.java

Expand|Select|Wrap|Line Numbers
  1. package com.kmg.employee;
  2. import org.apache.struts.action.ActionForm;
  3. public class employeeDetailForm extends ActionForm{
  4.  
  5.     private String empNo;
  6.     private String password;
  7.     private String fName;
  8.     private String mName;
  9.     private String lName;
  10.     private String dept;
  11.     private String desig;
  12.     private String address;
  13.  
  14.     public String getempNo() {
  15.         return empNo;
  16.     }
  17.     public void setempNo(String empNo) {
  18.         this.empNo = empNo;
  19.     }
  20.     public String getpassword() {
  21.         return password;
  22.     }
  23.     public void setpassword(String password) {
  24.         this.password = password;
  25.     }
  26.     public String getfName() {
  27.         return fName;
  28.     }
  29.     public void setfName(String name) {
  30.         fName = name;
  31.     }
  32.     public String getmName() {
  33.         return mName;
  34.     }
  35.     public void setmName(String name) {
  36.         mName = name;
  37.     }
  38.     public String getlName() {
  39.         return lName;
  40.     }
  41.     public void setlName(String name) {
  42.         lName = name;
  43.     }
  44.     public String getDept() {
  45.         return dept;
  46.     }
  47.     public void setDept(String dept) {
  48.         this.dept = dept;
  49.     }
  50.     public String getDesig() {
  51.         return desig;
  52.     }
  53.     public void setDesig(String desig) {
  54.         this.desig = desig;
  55.     }
  56.     public String getAddress() {
  57.         return address;
  58.     }
  59.     public void setAddress(String address) {
  60.         this.address = address;
  61.     }
  62.  
  63. }
  64.  
employeeDetailAction.java

Expand|Select|Wrap|Line Numbers
  1. package com.kmg.employee;
  2.  
  3. import com.kmg.employee.employeeDetailForm;
  4. import com.kmg.services.*;
  5.  
  6. import java.sql.Connection;
  7. import javax.servlet.http.*;
  8. import javax.sql.DataSource;
  9. import org.apache.struts.action.*;
  10.  
  11. public class employeeDetailAction extends Action {
  12.  
  13.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  14.             HttpServletRequest request, HttpServletResponse response)
  15.             throws Exception {
  16.         employeeDetailForm employeeDetailForm = (employeeDetailForm) form;
  17.         EmployeeDAO employeeDAO = new EmployeeDAO();
  18.         Employee employee = new Employee();
  19.  
  20.         Connection con = null;
  21.         DataSource ds = null;
  22.  
  23.         ds = getDataSource(request);
  24.         employee.setempNo(employeeDetailForm.getempNo());
  25.         String password = employeeDetailForm.getpassword();
  26.         String fName = employeeDetailForm.getfName();
  27.         String mName = employeeDetailForm.getmName();
  28.         String lName = employeeDetailForm.getlName();
  29.         String dept = employeeDetailForm.getDept();
  30.         String desig = employeeDetailForm.getDesig();
  31.         String address = employeeDetailForm.getAddress();
  32.         con = employeeDAO.getConnection(ds);
  33.         employee = employeeDAO.getRecord(con, employee);
  34.             employeeDAO.closeConnection(con);
  35.             return mapping.getInputForward();
  36.  
  37.     }
  38. }
  39.  
EmployeeDAO.java

Expand|Select|Wrap|Line Numbers
  1. package com.kmg.services;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7.  
  8. import javax.sql.DataSource;
  9.  
  10. public class EmployeeDAO {
  11.     public Connection getConnection(DataSource datasource) {
  12.         Connection con = null;
  13.         DataSource ds = datasource;
  14.         try {
  15.             con = ds.getConnection();
  16.         } catch (SQLException e) {
  17.             e.printStackTrace();
  18.         }
  19.         return con;
  20.     }
  21.  
  22.     public void closeConnection(Connection con) {
  23.         try {
  24.             con.close();
  25.         } catch (SQLException e) {
  26.             e.printStackTrace();
  27.         }
  28.     }
  29.  
  30.     public static Employee getRecord(Connection con, Employee employee) {
  31.         String qry = "select PASSWORD from EMP_MSTR where EMP_NO=?";
  32.         String password = null;
  33.         ResultSet resultSet = null;
  34.         try {
  35.             PreparedStatement pstat = con.prepareStatement(qry);
  36.             pstat.setString(1, employee.getempNo());
  37.             resultSet = pstat.executeQuery();
  38.             while (resultSet.next()) {
  39.                 employee.setpassword(resultSet.getString("PASSWORD"));
  40.                 employee.setfName(resultSet.getString("FNAME"));
  41.                 employee.setmName(resultSet.getString("MNAME"));
  42.                 employee.setlName(resultSet.getString("LNAME"));
  43.                 employee.setDept(resultSet.getString("DEPT"));
  44.                 employee.setDesig(resultSet.getString("DESIG"));
  45.                 employee.setAddress(resultSet.getString("ADDR"));
  46.             }
  47.         } catch (SQLException e) {
  48.             e.printStackTrace();
  49.         }
  50.  
  51.         return employee;
  52.     }
  53. }
  54.  
Employee.java

Expand|Select|Wrap|Line Numbers
  1. package com.kmg.services;
  2.  
  3. public class Employee {
  4.     private String empNo;
  5.     private String password;
  6.     private String fName;
  7.     private String mName;
  8.     private String lName;
  9.     private String dept;
  10.     private String desig;
  11.     private String address;
  12.     public String getempNo() {
  13.         return empNo;
  14.     }
  15.     public void setempNo(String empNo) {
  16.         this.empNo = empNo;
  17.     }
  18.     public String getpassword() {
  19.         return password;
  20.     }
  21.     public void setpassword(String password) {
  22.         this.password = password;
  23.     }
  24.     public String getfName() {
  25.         return fName;
  26.     }
  27.     public void setfName(String name) {
  28.         fName = name;
  29.     }
  30.     public String getmName() {
  31.         return mName;
  32.     }
  33.     public void setmName(String name) {
  34.         mName = name;
  35.     }
  36.     public String getlName() {
  37.         return lName;
  38.     }
  39.     public void setlName(String name) {
  40.         lName = name;
  41.     }
  42.     public String getDept() {
  43.         return dept;
  44.     }
  45.     public void setDept(String dept) {
  46.         this.dept = dept;
  47.     }
  48.     public String getDesig() {
  49.         return desig;
  50.     }
  51.     public void setDesig(String desig) {
  52.         this.desig = desig;
  53.     }
  54.     public String getAddress() {
  55.         return address;
  56.     }
  57.     public void setAddress(String address) {
  58.         this.address = address;
  59.     }
  60.  
  61. }
  62.  
struts-config.xml

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
  3.  
  4. <struts-config>
  5.   <data-sources>
  6. <data-source type="org.apache.commons.dbcp.BasicDataSource">
  7.     <set-property
  8.       property="driverClassName"
  9.       value="com.mysql.jdbc.Driver" />
  10.     <set-property
  11.       property="url"
  12.       value="jdbc:mysql://localhost:3306/bank_sys?autoReconnect=true" />
  13.     <set-property
  14.       property="username"
  15.       value="root"/>
  16.     <set-property
  17.       property="password"
  18.       value="hr"/>
  19.       </data-source>
  20.       </data-sources>
  21.    <form-beans>
  22.     <form-bean name="index1Form"
  23.                type="com.kmg.customer.Index1Form"/>
  24.  
  25.     <form-bean name="index2Form"
  26.                type="com.kmg.employee.Index2Form"/>
  27.  
  28.      <form-bean name="employeeDetailForm"
  29.                type="com.kmg.employee.employeeDetailForm"/>
  30.   </form-beans>
  31.  
  32.   <!-- Action Mappings Configuration -->
  33.   <action-mappings>
  34.     <action path="/index1"
  35.             type="com.kmg.customer.Index1Action"
  36.             name="index1Form"
  37.            input="/jsp/index1.jsp">
  38.            <forward name="accountDetail" path="/jsp/accountDetail.jsp"/>
  39.            </action>
  40.  
  41.            <action path="/index2"
  42.             type="com.kmg.employee.Index2Action"
  43.             name="index2Form"
  44.            input="/jsp/index2.jsp">
  45.            <forward name="employeeDetail" path="/jsp/employeeDetail.jsp"/>
  46.            </action>
  47.  
  48.            <action path="/employeeDetail"
  49.             type="com.kmg.employee.employeeDetailAction"
  50.             name="employeeDetailForm"
  51.            input="/jsp/employeeDetail.jsp">
  52.            </action>
  53.  
  54.   </action-mappings>
  55. </struts-config>
  56.  
  57.  

web.xml


Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  3.  
  4.  
  5.   <servlet>
  6.     <servlet-name>action</servlet-name>
  7.     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
  8.     <init-param>
  9.       <param-name>config</param-name>
  10.       <param-value>/WEB-INF/struts-config.xml</param-value>
  11.     </init-param>
  12.     <init-param>
  13.       <param-name>debug</param-name>
  14.       <param-value>3</param-value>
  15.     </init-param>
  16.     <init-param>
  17.       <param-name>detail</param-name>
  18.       <param-value>3</param-value>
  19.     </init-param>
  20.     <load-on-startup>0</load-on-startup>
  21.   </servlet>
  22.   <servlet-mapping>
  23.     <servlet-name>action</servlet-name>
  24.     <url-pattern>*.do</url-pattern>
  25.   </servlet-mapping>
  26.   <welcome-file-list>
  27.     <welcome-file>/jsp/employeeDetail.jsp</welcome-file>
  28.   </welcome-file-list>
  29.  
  30.  
  31. </web-app>
  32.  
  33.  
I am sorry for posting all the code if its against the community guide lines.
But I really need help. I m SOO lost. How to display data retrieved from database using JSP file ?? Nothing is getting displayed when I run the JSP file.
Apr 13 '09 #1
12 77930
NitinSawant
270 Contributor
Okay, seems that you are newbie,

hey buddy you've already done the code for retrieving the data from database
checkout EmployeeDAO.java

Click: JSP Database Connectivity Code

hope it works
Apr 13 '09 #2
lifeisgreat20009
70 New Member
Yes I know the code to retrieve is there in that DAO class..
But how do I display it ?? I mean I have used the <bean:write > tag in my JSP file but its not displaying any value.

How can I write the code for DB connection and data retrieval again in my JSP when I have already made a separate class for that purpose i.e EmployeeDAO.java

Why is it not getting displayed ? Is there some problem with <bean:write > tag ?

Also when I hover mouse on <bean:write> tag
it says "unknown tag bean:write"

Whats wrong with it ?
Apr 13 '09 #3
NitinSawant
270 Contributor
At the top of the jsp page, just above the <html> tag write following lines:-

Expand|Select|Wrap|Line Numbers
  1. <%@ page language="java" %>
  2. <%@ taglib uri="/WEB-INF/struts-bean.tld"   prefix="bean" %>
  3.  
Apr 13 '09 #4
lifeisgreat20009
70 New Member
I just included the line below in my JSP file. It doesn't show the error "unknown tag bean:write" anymore.

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

Now that I am running my file it says :-
I know the error has to do something with name and property attributes I have given in the <bean:write> tag .. I am just not able to figure out. Please help me guys.


exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/employeeDetail.jsp at line 69

66: <td>
67: <div>Employee No.</div>
68: </td>
69: <td><bean:write name="employeeDetailForm" property="empNo"/></td>
70: </tr><tr></tr><tr></tr><tr></tr>
71: <tr valign="top">
72: <td>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)


root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean employeeDetailForm in any scope
org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:852)
org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:781)
org.apache.jsp.jsp.employeeDetail_jsp._jspService( employeeDetail_jsp.java:275)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)


root cause

javax.servlet.jsp.JspException: Cannot find bean employeeDetailForm in any scope
org.apache.struts.taglib.TagUtils.lookup(TagUtils. java:992)
org.apache.struts.taglib.bean.WriteTag.doStartTag( WriteTag.java:227)
org.apache.jsp.jsp.employeeDetail_jsp._jspx_meth_b ean_005fwrite_005f0(employeeDetail_jsp.java:294)
org.apache.jsp.jsp.employeeDetail_jsp._jspService( employeeDetail_jsp.java:131)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
Apr 13 '09 #5
lifeisgreat20009
70 New Member
Oh I just did that only..
Now its giving another error :(

I am sure it has something to do with the name and property attribute in the <bean:write> tag in my JSP file.
Apr 13 '09 #6
NitinSawant
270 Contributor
you have to define employeeDetailForm on the jsp page
Apr 13 '09 #7
lifeisgreat20009
70 New Member
u mean i need to import that employeeDetailsForm.java file in my JSP file or what ??

What do u mean by define ?
create object of it in JSP file ??

Seriously my mind has stopped working ...
I am struggling with this code for like 6-7 hours now and I need to complete it today only
Apr 13 '09 #8
lifeisgreat20009
70 New Member
ok in my DAO class I have retrieved all fields from the emp_mstr table in the getRecords() method and returning the Employee object ..

Now how do I use this object in my JSP page to display the values of all the fields that it contains ??

god I am sooo lost :(
Apr 13 '09 #10
Anbu007
1 New Member
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-menu.tld" prefix="menu"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<%@ taglib uri="/WEB-INF/innovation.tld" prefix="innov"%>

import in your jsp... u should have those tld file in your WEB-INF folder. you can download tld from internet.

http://www.allapplabs.com/struts/struts_example.htm
http://j2ee.masslight.com/Chapter5.html

use the above link for your reference
Sep 15 '10 #11
raj1001
1 New Member
I have displayed id,x co-od,y co-od,color of points.Hope it helps.
struts-config.xml
Expand|Select|Wrap|Line Numbers
  1. <action-mappings>
  2.         <action name="pointForm" path="/add" scope="request" type="com.myapp.sruts.NewAction" validate="false">
  3.             <forward name="success" path="/WEB-INF/add.jspx"/>
  4.         </action>
  5.         <action path="/addSubmit" name="pointForm" scope="request" input="/add.do" type="com.myapp.struts.AddAction">
  6.             <forward name="success" path="/WEB-INF/list.jsp"/>
  7.  
  8.         </action>
  9.  
list.jsp
Expand|Select|Wrap|Line Numbers
  1. <%@page contentType="text/html"%>
  2. <%@page pageEncoding="UTF-8"%>
  3. <%@ page import="java.sql.*" %>
  4. <%@ page import="java.io.*" %>
  5. <html>
  6. <head>
  7. <title>display data from the table using jsp</title>
  8. </head>
  9. <body>
  10. <h2>Data from the table point </h2>
  11. <%
  12. try {
  13. /* Create string of connection url within specified format with machine
  14. name, port number and database name. Here machine name id localhost and
  15. database name is student. */
  16. String connectionURL = "jdbc:odbc:poi";
  17. // declare a connection by using Connection interface
  18. Connection connection = null;
  19. /* declare object of Statement interface that is used for executing sql
  20. statements. */
  21. Statement statement = null;
  22. // declare a resultset that uses as a table for output data from tha table.
  23. ResultSet rs = null;
  24. // Load JBBC driver "com.mysql.jdbc.Driver"
  25. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  26. /* Create a connection by using getConnection() method that takes parameters
  27. of string type connection url, user name and password to connect to database.*/
  28. connection = DriverManager.getConnection(connectionURL, "s", "s");
  29. /* createStatement() is used for create statement object that is used for
  30. sending sql statements to the specified database. */
  31. statement = connection.createStatement();
  32. // sql query to retrieve values from the secified table.
  33. String QueryString = "SELECT * from point";
  34. rs = statement.executeQuery(QueryString);
  35. %>
  36. <TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
  37. <tr>
  38.     <td>id</td>
  39.     <td>x</td>
  40.     <td>y</td>
  41.     <td>color</td>
  42.  </tr>
  43. <%
  44. while (rs.next()) {
  45. %>
  46. <TR>
  47. <TD><%=rs.getInt(1)%></TD>
  48. <TD><%=rs.getDouble(2)%></TD>
  49. <TD><%=rs.getDouble(3)%></TD>
  50. <TD><%=rs.getString(4)%></TD>
  51. </TR>
  52. <% } %>
  53. <%
  54. // close all the connections.
  55. rs.close();
  56. statement.close();
  57. connection.close();
  58. } catch (Exception ex) {
  59. %>
  60.  
  61.  
  62. <%
  63. out.println("Unable to connect to database.");
  64. }
  65. %>
  66. </TABLE><TABLE>
  67. <TR>
  68. <TD>
  69. <button type="submit"><-- back</button></TD>
  70. </TR>
  71. </TABLE>
  72. </body>
  73. </html>
  74.  
Apr 13 '12 #12
abhijitbhopale
1 New Member
http://r4r.co.in/java/struts/basic/t...Struts%20Basic

go with this link this will help you solve your problem
May 25 '13 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2072
by: Miki | last post by:
Hi. I have a IIS server with php3 installed. I have SQL server database and data stored in unicode format (nvarchar fields). In header of my php I have the meta: <meta HTTP-EQUIV="content-type"...
4
3921
by: Claudia Fong | last post by:
Hi, I have a form where I need to display the data of a department that stores in a access db. When I first load the form it will call a function name loaddata which will get the first...
1
3238
by: funcSter | last post by:
I want to retrieve data from an Excel file like how I would with a database. I understand that I would have to use OLE DB. Somehow I think I cannot get the connection string right, as the bit of...
5
2416
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
1
6518
by: RajithaV | last post by:
Hi, I am developing a web application using ASP.Net I am using sql server.My coding is in VB.net I want to know how to move data from excel file into the Database. I also need to know how to...
1
4885
by: Ryan | last post by:
Hi, I'm trying to do retrieve some data from a table where the content is in Greek, however, the query is not working. It's a very simple statement, but I'm missing something. Here is the...
5
2074
by: fruityfreak | last post by:
I would like to know how to I retrieve information from another database table... Instead of keying in manually, I would like to retrieve data directly from the logged in user row. For the user...
0
2512
by: ghjk | last post by:
I want to insert web application data to mysql database. I'm using struts, jsp and hibernet.This is my action class. public ActionForward execute(ActionMapping mapping, ActionForm form, ...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.