<%@ taglib uri="WEB-IN" name="description">

my Code Given below Pls... help me send correct code for me
jsp file... <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ 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" %>
<html:html>
<head>
<html:base/>
<title>Login page</title>
</head>
<body onload ="getDestArray()">
<html:form action="/dedit" >
<center><table border="1">
<tbody>
<tr>
<td>Destination : </td>
<td>
<html:select property="destination" onchange="getPrice()">
<html:option value="0">?SELECT?</html:option>
<html:options collection="menuList" property="destination" />
</html:select>
</td>
</tr>
<tr>
<td>Amount : </td>
<td id="price"><input type="text" value =" " property= "amount" id='pricecheck'/>
<html:text value="" property="amount"/></td>
</tr>
<tr>
<td colspan="2" valign="center"><html:submit value="Submit"/></td></tr>
</tbody>
</table></center>
</html:form>
</body>
</html:html>
<script>
var destArray=new Array();
function getDestArray(){
<logic:notEmpty name="form" property="arrPriceLis">
<logic:iterate name="form" property="arrPriceLis" id="priceList ">
destArray ["<bean:write name= 'priceList' property='destination'/>"] = "<bean:write name= 'pricelist' property= 'priceList' />";
</logic:iterate>
</logic:notEmpty>
}
function getPrice(){
var test =<bean:write name="menuBeanList" property="destArray"></bean:write>
//var test = document.forms[0].destination.value;
var price = destArray ["test"];
// try these stuff any one
document.forms[0].amount.value = price;
// else try this if its input tag
//document.getElementById('pricecheck').value= price;
// else IF ITS HYML TAG
//document.getElementById('price').innerHTML = PRICE
}
</script>
Action class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fetch;
import java.sql.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import fetch.MenuBean;
public class MenuAction extends Action {
private final static String SUCCESS = "success";
public ActionForward execute(ActionMapping mapping, ActionForm actionform,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ArrayList menuList = new ArrayList();
ArrayList menuBeanList = new ArrayList();
MenuBean menu = null;
MenuCombo menucombo = null;
MenuForm form = new MenuForm();
HttpSession session = request.getSession();
session.setAttribute( "menuList", menuList);
// ELSE DO THIS
//MenuForm form = (MenuForm)actionform;
// thtas is to cascate ur form
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","thiru","thirumal");
PreparedStatement stmt=con.prepareStatement("select * from destination");
ResultSet rs=stmt.executeQuery();
while(rs.next())
{
menucombo=new MenuCombo();
menu = new MenuBean();
String destination = rs.getString(1);
String destinationId = rs.getString(1);
String price = rs.getString(2);
menucombo.setDestination(destination);
menucombo.setDestinationId(destinationId );
menu.setDestination(destination );
menu.setPrice(price );
menuList.add(menucombo);
menuBeanList.add(menu);
}
form.setArrPriceList(menuBeanList);
form.setMenuList(menuList);
}
catch(Exception e)
{
}
return mapping.findForward(SUCCESS);
}
}
bean class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fetch;
/**
*
* @author Thiru
*/
public class MenuBean {
private String destination;
private String price;
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
java class
package fetch;
/**
*
*/
public class MenuCombo {
private String destination ;
private String destinationId;
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public String getDestinationId() {
return destinationId;
}
public void setDestinationId(String destinationId) {
this.destinationId = destinationId;
}
}
DAO class
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fetch;
/**
*
* @author Thiru
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.sql.*;
import java.util.ArrayList;
import fetch.MenuBean;
public class MenuData {
public MenuData() {
}
public ArrayList menuList() {
ArrayList menuList = new ArrayList();
ArrayList menuBeanList = new ArrayList();
MenuBean menu = null;
MenuCombo menucombo = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","thiru","thirumal");
PreparedStatement stmt=con.prepareStatement("select * from destination");
ResultSet rs=stmt.executeQuery();
while(rs.next())
{
menucombo=new MenuCombo();
menu = new MenuBean();
String destination = rs.getString(1);
String destinationId = rs.getString(1);
String price = rs.getString(2);
menucombo.setDestination(destination);
menucombo.setDestinationId(destinationId );
menu.setDestination(destination );
menu.setPrice(price );
menuList.add(menucombo);
menuBeanList.add(menu);
}
}
catch(Exception e)
{
}
return menuList;
}
}
list getter and setter
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fetch;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
/**
*
* @author Thiru
*/
public class MenuForm extends org.apache.struts.action.ActionForm {
private ArrayList arrPriceList;
private String amount;
private String destination;
private ArrayList menuList;
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
public ArrayList getArrPriceList() {
return arrPriceList;
}
public void setArrPriceList(ArrayList arrPriceList) {
this.arrPriceList = arrPriceList;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public ArrayList getMenuList() {
return menuList;
}
public void setMenuList(ArrayList menuList) {
this.menuList = menuList;
}
}
thank U
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.