I am getting null point error. I am currently trying to connect my spring mvc with mysql.

The problem arises when I try to implement "@RequestMapping" part in Homecontroller file. If i remove this it works fine.

SELECT * FROM details_rssi WHERE Username='pranay@gmail.com' AND Password='ws014';
Sep 09, 2014 12:46:58 PM org.apache.catalina.core.StandardWrapperValve invoke

SEVERE: Servlet.service() for servlet [appServlet] in context with path [/web] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
    at com.main.web.HomeController.general(HomeController.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)

Homecontroller.java file::

/**
 * Handles requests for the application home page.
 */
@SuppressWarnings("unused")
@Controller
public class HomeController {

    private static final Logger logger = LoggerFactory
            .getLogger(HomeController.class);

    /**
     * Simply selects the home view to render by returning its name.
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home() {

        return "home";

    }

    @RequestMapping(method = RequestMethod.POST)
    public String general(HttpServletRequest request, Model model) {
        conproject obj=new conproject();
        String un=request.getParameter("txtuname");
        String pass=request.getParameter("txtpass");
            try {

            Connection con = obj.getcon();
            String qry = "SELECT * FROM details_rssi WHERE Username='" + un
                    + "' AND Password='" + pass + "';";
            System.out.println(qry);
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(qry);

            if (rs.next()) {
                //HttpSession session = request.getSession();
                //session.setAttribute("user", un);
                return "login_succ";
            } else {

                return "home.jsp";
            }

        } catch (SQLException e) {

        } 
        return "login_succ";

    }

    /**
     * @return the logger
     */
    public static Logger getLogger() {
        return logger;
    }
}

Related posts

Recent Viewed