09Q71AO534
09Q71AO534

Reputation: 4440

How to call a function with parameters in a java file from a jsp file?

i have the emp.java file with method as

    boolean create(int empid,String empname,int supid );

i have the register.jsp page as

 <form name="register" action="#" method="post">
        <table>
                                <tr>
                                    <td>Employee Id</td>
                                    <td><input type="text" name="empid"
                                        placeholder="Enter Employee Id " size="30"></td>
                                </tr>
                                <tr>
                                    <td>Employee Name</td>
                                    <td><input type="text" name="empname"
                                        placeholder="Enter Employee Name " size="30"></td>
                                </tr>
                                <tr>
                                    <td>Supervisor Id</td>
                                    <td><input type="text" name="sup_id"
                                        placeholder="Enter Supervisor Id" size="30"></td>
                                </tr>
                                <tr>
                                    <td colspan="2" align="justify"><input type="submit"
                                        value="Submit"></td>


                                </tr>
                                </table>
    </form>

My requirement is as i click the submit button the emp.create() must be called with the parameters entered in the register.jsp page.... Is there any way to solve this? What are the necessary things which i have to change so that i can reach my requirement!

or is there any way that i can pass my values to the employee-->create(employee e)

....
{
 callableStatement = openConnection().prepareCall("{call insert_employee(?,?,?)}");
                callableStatement.setInt(1,employee.getempid());
                callableStatement.setString(2,employee.getempname());
                callableStatement.setInt(3,employee.getsupid());    
}
...

as a object(*) all values when i click submit?

Upvotes: 1

Views: 9072

Answers (3)

09Q71AO534
09Q71AO534

Reputation: 4440

Add This into the RegisterDao.jsp file

<%          Object function_name(call the function of the callable stmt) = new Object();
        int empid = Integer.parseInt(request.getParameter("empid"));
        String empname = request.getParameter("empname");
        int supid = Integer.parseInt(request.getParameter("supid"));

        int status = function_name.method(empid, empname, supid);

        if (status > 0) {
            //out.println("Employee is created");
    %>//jsp code to display if he is te employee
<%
        session.setAttribute("session", "TRUE");
        } else {
            out.println("Creation failed");
        }
    %>

Upvotes: 1

Sandiip Patil
Sandiip Patil

Reputation: 446

You need a servlet class which will call your emp.java classes' method. The servlet class should work as your action for register.jsp. In the servlet you can do request.getparameter/attribute()and collect the values of input types using their name/id.

Pass these values to either a method or callable anywhere you want to use. If you want to stay on the same jsp after your processing then you need to use ajax.

Upvotes: 1

user2028750
user2028750

Reputation:

create a bean which should have getter and setter methods of the fields that accepts inputs in the register page and also inside the bean create your method

boolean create(int empid,String empname,int supid );

now you form action should call a another jsp and it should have these methods in the head

<jsp:useBean id="" class=""></jsp:useBean>

Upvotes: 0

Related Questions