• 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

Displaying Database values on jsp page in struts 1.3

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

hello Friends
I am using struts 1.4 for my project developement.In my useprofile.jsp there is dropdown control is there from which user can select the country from the list.
the countries are from the database table.So i want to display the country All countries from the database table country on jsp page country.jsp
So for that i am writing one country hadler ,one jsp page,one also i am giving my struts-config.xml content
So kindly give me reply

CountryHandler.java

package com.udhc.handler;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import com.udhc.model.Country;
import com.udhc.utility.LogUtility;

public class CountryHandler
{
Logger log=Logger.getLogger(CountryHandler.class);
Connection conn=null;

public CountryHandler(Connection conn)
{
this.conn=null;
}

public Country addCountry(Country country)throws Exception
{
int autoGenId=0;
PreparedStatement pstmt=null;
Country country2=null;
try
{
String sql="INSERT INTO country(NAME,SHORT_NAME,ISO_CODE,CURRENCY) VALUES(?,?,?,?)";
pstmt=conn.prepareStatement(sql);
pstmt.setInt(1,country.getCountryId());
pstmt.setString(2,country.getName());
pstmt.setString(3,country.getShortName());
pstmt.setString(4,country.getIsoCode());
pstmt.setString(5,country.getCurrency());

int count=pstmt.executeUpdate();
if(count>0)
{
ResultSet rs=pstmt.getGeneratedKeys();
rs.next();
autoGenId=rs.getInt(1);
rs=pstmt.executeQuery();

}
}
catch (SQLException e)
{
// TODO: handle SQL exception
log.error("SQL Exception" +e.getMessage());
LogUtility.printStackTrace(e.getStackTrace());
}

catch (Exception e)
{
// TODO: handle SQL exception
log.error("Exception" +e.getMessage());
LogUtility.printStackTrace(e.getStackTrace());
}

return country2;
}

public Country getCountry(ArrayList <Country> countryList )throws Exception
{
PreparedStatement pstmt=null;
Country country2=null;
ResultSet rs=null;

ArrayList <Country> countryList1=new ArrayList<Country>();
try
{
String sql="SELECT COUNTRY_ID,NAME,SHORT_NAME,ISO_CODE,CURRENCY FROM country WHERE COUNTRY_ID=?";
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();

while(rs.next())
{
country2=new Country();
country2.setCountryId(rs.getInt(1));
country2.setName(rs.getString(2));
country2.setShortName(rs.getString(3));
country2.setIsoCode(rs.getString(4));
country2.setCurrency(rs.getString(5));
}

log.info("Country Name" +countryList1.size());

}
catch (SQLException e)
{
// TODO: handle exception
log.error("SQLException"+e.getMessage());
LogUtility.printStackTrace(e.getStackTrace());
}
catch (Exception e)
{
// TODO: handle exception
}
return country2;
}
}


country.jsp

<%@ 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">
<%@page import="java.util.ArrayList"%>
<%@page import="com.udhc.model.City"%>
<%@page import="com.udhc.model.Country"%>
<%@page import="com.udhc.model.State"%>

<%@page import="com.udhc.config.ApplicationConstant"%>
<%@page import="com.udhc.model.User"%>
<%@page import="com.udhc.model.Professional"%>
<%@page import="org.apache.struts.Globals"%>


<jsp:include page="Header.jsp"></jsp:include>

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

<script type="text/javascript" >
function addCountry(tableID)
{
var table = document.getElementById(tableID);
var rowCount = table.rows.length;

var row = table.insertRow(rowCount);

var cell1 = row.insertCell(0);
var cell5;
cell1.innerHTML = "<input type='text' name='text_c"+rowCount+"' class=\"textfield\"/>";

cell5.innerHTML = "<a href=\"#\" color=\"red\" onClick=\"javascript:addToList(this);\" >Add</a>";
}

function getUDHCCountry(cId)
{
document.forms[0].countryId.value=cId;
document.forms[0].nextStep.value = "getCountry";
document.forms[0].action = "Admin.do";
document.forms[0].submit();
}

function addUDHCCountry(cId)
{
document.forms[0].countryId.value=cId;
document.forms[0].nextStep.value = "addCountry";
document.forms[0].action = "Admin.do";
document.forms[0].submit();
}
</script>


<input type="hidden" name="countryId"></input>
<bean:define id="professionalModel" name="UDHC_USER_MODEL" scope="session"></bean:define>
<div><a href="Admin_MasterManagement.jsp">Back</a></div>
<table width="100%" class="back_img" height="300">
<logic:messagesPresent message="true">
<tr>
<td valign="top" style="height: 20px;">
<html:messages id="message" message="true">
<div class="success">
<bean:write name="message"/>
</div>
</html:messages>
</td>
</tr>
</logic:messagesPresent>
<tr valign="top">
<td valign="top" align="center">
<logic:present name="COUNTRY_LIST">
<div style="height: 480px; overflow: auto;">
<table width="80%" class="border" style="margin-top: 60px;">
<tr valign="top">
<td align="left" valign="top" colspan="8"><b><u>Professional List : </u></b></td>
</tr>
<tr class="background1" valign="top" style="font-weight: bold;">
<td width="5" align="center">Sr.No</td>
<td width="30" align="center">Name</td>
<td width="10" align="center">Short Name</td>
<td width="20" align="center">ISO Code</td>
<td width="10" align="center">Currency</td>
</tr>
<% int i=0; %>
<logic:iterate id="countryList" name="COUNTRY_LIST">
<tr>
<td width="5" align="left"><%=++i%></td>
<td width="30" align="left"><bean:write name="countryList" property="name" /></td>
<td width="10" align="center"><bean:write name="countryList" property="shortName" /></td>
<td width="20" align="left"><bean:write name="countryList" property="isoCode" /></td>
<td width="10" align="left"><bean:write name="countryList" property="currency" /></td>
</tr>
</logic:iterate>
</table>
</div>
</logic:present>
<logic:notPresent name="COUNTRY_LIST">
<b>Country List is empty.</b>
</logic:notPresent>
</td>
<td valign="top">
<a href="javascript:addCountry('countries')">Add Country</a>
</td>
</tr>

</table>


<jsp:include page="Footer.jsp"></jsp:include>

struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<form-beans>
<form-bean name="LoginForm" type="com.udhc.form.LoginForm"></form-bean>
<form-bean name="UserForm" type="com.udhc.form.UserForm"></form-bean>
<form-bean name="ProfessionalForm" type="com.udhc.form.ProfessionalForm"></form-bean>

</form-beans>

<global-forwards>
<forward name="default" path="/index.jsp" />
</global-forwards>

<action-mappings>
<action path="/Login" type="com.udhc.action.LoginAction" name="LoginForm">
<forward name="consent" path="/Consent.jsp"></forward>
<forward name="welcome" path="/Welcome.jsp"></forward>
<forward name="disclaimer" path="/Disclaimer.jsp"></forward>
<forward name="adminHome" path="/Admin_Home.jsp"></forward>
<forward name="userHome" path="/User.do?nextStep=userHome"></forward>
<forward name="professionalHome" path="/Professional.do?nextStep=professionalHome"></forward>
<forward name="default" path="/index.jsp"></forward>
</action>

<action path="/User" type="com.udhc.action.UserAction" name="UserForm">
<forward name="viewUserRegForm" path="/User_Registration.jsp"></forward>
<forward name="userRegistrationSuccess" path="/Consent.jsp"></forward>
<forward name="userRegistrationFail" path="/User_Registration.jsp"></forward>
<forward name="userHome" path="/User.do?nextStep=userHome"></forward>
<forward name="userHomePage" path="/User_Home.jsp"></forward>
<forward name="updateImageSuccessfully" path="/User.do?nextStep=userHome"></forward>
<forward name="userUpdationSuccess" path="/User.do?nextStep=userHome"></forward>
<forward name="userUpdationFail" path="/User.do?nextStep=userHome"></forward>
<forward name="updateUser" path="/User_Registration.jsp"></forward>
</action>

<action path="/Professional" type="com.udhc.action.ProfessionalAction" name="ProfessionalForm">
<forward name="viewProfessionalRegForm" path="/Professional_Registration.jsp"></forward>
<forward name="professinalRegistrationSuccess" path="/Disclaimer.jsp"></forward>
<forward name="duplicateRequest" path="/Disclaimer.jsp"></forward>
<forward name="professinalRegistrationFail" path="/Professional_Registration.jsp"></forward>
<forward name="professionalHome" path="/Professional.do?nextStep=professionalHome"></forward>
<forward name="professionalHomePage" path="/Professional_Home.jsp"></forward>
<forward name="viewUsersList" path="/UsersList.jsp"></forward>
<forward name="viewProfessionalList" path="/ProfessionalList.jsp"></forward>
<forward name="viewProfessionalProfile" path="/Professional_Profile.jsp"></forward>
<forward name="userDetailsForProfessional" path="/User_Profile.jsp"></forward>
</action>

<action path="/ReceiveSms" type="com.udhc.action.ReceiveSMSContentAction" name="ProfessionalForm">
<forward name="smsContentSuccess" path="/SMSSuccess.jsp"></forward>
<forward name="smsContentFail" path="/index.jsp"></forward>
</action>

<action path="/Consulting" type="com.udhc.action.ConsultingAction">
<forward name="userHome" path="/User.do?nextStep=userHome"></forward>
</action>

<action path="/Discussion" type="com.udhc.action.DiscussionAction">
<forward name="userHome" path="/User.do?nextStep=userHome"></forward>
<forward name="getUserProfile" path="/User_Profile.jsp"></forward>
</action>

<action path="/Admin" type="com.udhc.action.AdminAction">
<forward name="adminHome" path="/Admin_Home.jsp"></forward>
<forward name="viewProfessionals" path="/Admin_ViewProfessionalList.jsp"></forward>
<forward name="viewProfessionalProfile" path="/Professional_Profile.jsp"></forward>
<forward name="statusUpdateSuccess" path="/Admin.do?nextStep=viewProfessionalList"></forward>
<forward name="masterManagement" path="/Admin_MasterManagement.jsp"></forward>
<forward name="countryManagement" path="/Country.jsp"></forward>
<forward name="stateManagement" path="/State.jsp"></forward>
<forward name="cityManagement" path="/City.jsp"></forward>
</action>


<action path="/Register" type="com.udhc.action.RegistrationAction">
<forward name="stateList" path="/GetStateListByCountry.jsp"></forward>
<forward name="cityList" path="/GetCityListByState.jsp"></forward>
</action>

<action path="/GeneralDiscussion" type="com.udhc.action.GeneralDiscussionAction">
<forward name="discussionAddedSuccess" path="/GeneralDiscussion.do?nextStep=viewAllGeneralDiscussions"></forward>
<forward name="viewGeneralDiscussions" path="/GeneralDiscussion.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="resources.ApplicationResources" />
</struts-config>

So please give me a solution


 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic