-3
package com.dev.web.Controller;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dev.web.Dao.UserDao;
import com.dev.web.Model.User;

public class UserControll extends HttpServlet
{
    private static final long serialVersionUID = 1L;
    private static String INSERT_OR_EDIT = "/user.jsp";
    private static String LIST_USER = "/listEmp.jsp";
    private UserDao dao;

    public UserControll() {
        super();
      UserDao dao = new UserDao();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String forward="";
        String action = request.getParameter("action");

        if (action.equalsIgnoreCase("delete")){
            int Employee_Id= Integer.parseInt(request.getParameter("Employee_Id"));
            dao.deleteUser(Employee_Id);
            forward = LIST_USER;
            request.setAttribute("users", dao.getAllUsers());    
        } else if (action.equalsIgnoreCase("edit")){
            forward = INSERT_OR_EDIT;
            int Employee_Id = Integer.parseInt(request.getParameter("empId"));
            User user = dao.getUserById(Employee_Id);
            request.setAttribute("user", user);
        } else if (action.equalsIgnoreCase("listUser")){
            forward = LIST_USER;
            request.setAttribute("Employee", dao.getAllUsers());
        } else {
            forward = INSERT_OR_EDIT;
        }

        RequestDispatcher view = request.getRequestDispatcher(forward);
        view.forward(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = new User();
        user.setEmployee_Name(request.getParameter("empname"));
        user.setSalary(request.getParameter("empsalary"));// here is my error..i declared salary is double
        try {
            Date dob = new SimpleDateFormat("MM/dd/yyyy").parse(request.getParameter("empdob"));
            user.setDob(dob);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        user.setActive(request.getParameter("empactive"));// here is my error.. i declared active is boolean
        String empid = request.getParameter("empid");
        if(empid == null || empid.isEmpty())
        {
            dao.addUser(user);
        }
        else
        {
            user.setEmployee_ID(Integer.par`enter code here`seInt(empid));
            dao.updateUser(user);
        }
        RequestDispatcher view = request.getRequestDispatcher(LIST_USER);
        request.setAttribute("users", dao.getAllUsers());
        view.forward(request, response);
    }
}
Naman
  • 2,205
  • 2
  • 19
  • 32
sairam
  • 25
  • 1
  • 2
  • 4
  • First, format your code to understand clearly. – SatyaTNV Jul 14 '15 at 05:26
  • 1
    Post some more details, all you have posted is only code and nothing to explain, go to help page and refer the "Asking" section in the page. http://stackoverflow.com/help – Bilbo Baggins Jul 14 '15 at 05:27
  • i declared salary as double in set&get value but when i execute the control statement it tells"The method setSalary(Double) in the type User is not applicable for the arguments (String) – sairam Jul 14 '15 at 05:30
  • 1
    If you plan to do any math on `salary` stop using `double` or Richard Pryor will embezzle all your fractional pennies. http://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represent-currency – candied_orange Jul 14 '15 at 05:36
  • no i did't do any math on salary , just enter emp salary in that – sairam Jul 14 '15 at 05:39

1 Answers1

2

The getParameter() method of HttpServletRequest is inherited from ServletRequest. From the API docs you can see this method always returns a string. You need to parse your boolean or double from this string, for example

Double.parseDouble(request.getParameter("empsalary"));
milez
  • 2,201
  • 12
  • 31