Results 1 to 9 of 9
  1. #1
    Thirumal is offline Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0

    Exclamation Struts : edit database based on selected value

    hi...
    I'm new for struts. i need code for edit database based on selected value
    in struts+jsp

    pls... help me this will help for my project...

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Struts : edit database based on selected value

    Um...that's far too vague.
    What have you written and which bit doesn't work, including any exceptions/errors and identifying the line they occur on in your code.
    Break the problem down.
    Get struts talking to your servlet, passing the data to update.
    Write a class (a DAO) that will take data to update a row in a table.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Thirumal is offline Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0

    Default Re: Struts : edit database based on selected value

    i need to fetch student detail into text box based on student id
    tht's my problem code for tht and in struts and jsp....

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Struts : edit database based on selected value

    SO what code do you alread have?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Thirumal is offline Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0

    Default Re: Struts : edit database based on selected value

    .Jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <%@ 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>

    Menu.java
    package DestinationEdit;

    public class Menu {



    /** Creates a new instance of Menu */

    public Menu() {

    }



    String destination;



    public String getDestination() {
    return destination;
    }

    public void setDestination(String destination) {
    this.destination = destination;
    }

    public Menu(String destination)
    {
    this.destination=destination;
    }
    }

    MenuForm.java
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package DestinationEdit;

    import javax.servlet.http.HttpServletRequest;

    import org.apache.struts.action.ActionErrors;

    import org.apache.struts.action.ActionMapping;

    import org.apache.struts.action.ActionMessage;



    public class MenuForm extends org.apache.struts.action.ActionForm {



    public String destination;


    public String getDestination() {
    return destination;
    }

    public void setDestination(String destination) {
    this.destination = destination;
    }
    public MenuForm() {

    super();

    // TODO Auto-generated constructor stub

    }
    }

    MenuDAO.java
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package DestinationEdit;

    /**
    *
    * @author Thirumal
    */
    import java.sql.*;
    import java.util.ArrayList;



    public class MenuData {



    public MenuData() {

    }



    public ArrayList menuList() {



    ArrayList menuList = new ArrayList();



    Menu menu = null;

    try
    {
    System.out.println("WELCOME");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("WELCOME");
    Connection con=DriverManager.getConnection("jdbc:oracle:thin: @localhost:1521:XE","thiru","thirumal");
    System.out.println("WELCOME");
    PreparedStatement stmt=con.prepareStatement("select Destination from destination");
    System.out.println("WELCOME");
    ResultSet rs=stmt.executeQuery();
    System.out.println("WELCOME");
    //int i=0;
    while(rs.next())
    {

    System.out.println("WEL");
    menu=new Menu(rs.getString(1));
    System.out.println("WELC");
    menuList.add(menu);
    System.out.println("WELCO");
    }

    }
    catch(Exception e)
    {

    }


    return menuList;



    }
    }

    MenuAction.java

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package DestinationEdit;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;

    /**
    *
    * @author Thirumal
    */
    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;



    public class MenuAction extends Action {



    private final static String SUCCESS = "success";



    public ActionForward execute(ActionMapping mapping, ActionForm form,

    HttpServletRequest request, HttpServletResponse response)

    throws Exception {



    ArrayList menuList = new ArrayList();

    MenuData menuData = new MenuData();

    menuList = menuData.menuList();



    HttpSession session = request.getSession();

    session.setAttribute( "menuList", menuList);



    return mapping.findForward(SUCCESS);



    }

    }


    This is my code pls... help...

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Struts : edit database based on selected value

    Please use [code] tags [/code] when posting code.

    So what bit doesn't work?
    Do you get the data you need in the Action?
    Does that data get into the DAO.
    Does the DAO manage to make calls to the database?

    ...in short, help us to help you.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    Thirumal is offline Member
    Join Date
    Jun 2012
    Posts
    4
    Rep Power
    0

    Default Re: Struts : edit database based on selected value

    i have problem in jsp page...

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Struts : edit database based on selected value

    And?
    That's like taking your car to a garage and saying "I have a problem with my car" and expecting them to fix it without any other information.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Struts : edit database based on selected value

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 10-01-2011, 04:13 AM
  2. create,edit ,delete in JSP usin struts and SQL server as database in jdeveloper
    By gurpreet.singh in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-11-2011, 12:43 PM
  3. Add , edit ,delete code in struts
    By sandy1000 in forum Web Frameworks
    Replies: 0
    Last Post: 12-28-2010, 06:25 AM
  4. options already selected from dropdown list based on database request.
    By sauravsinha in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-29-2010, 10:46 AM
  5. Replies: 1
    Last Post: 07-14-2009, 05:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •