开发者

How to write an action class for an MVC web application in JSP?

I have followed this tutorial for developing a Java EE application in MVC pattern. But I was asked to write an action cl开发者_开发技巧asses for complete MVC. The tutorial does not contain an action class.

What is the use of an action class and how to create one?


action class is basically your controller which processes the request made by client to server ..

login usinh jsp ..(if ur using lookupdispatch action)

package com.pra.loginmodel;

public class LoginAction extends LookupDispatchAction {

    /*
     * forward name="success" path=""
     */
    private static final String SUCCESS = "success";

    @Override
    protected Map getKeyMethodMap() {
        Map map = new HashMap();
        map.put("UserForm.login", "login");
        return map;
    }

    public ActionForward login(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        LoginActionFormBean lafb = (LoginActionFormBean) form;
        String userid = lafb.getUserid();
        if (!"false".equals(lafb.loginvalidate())) {
            HttpSession session = request.getSession();
            session.setAttribute("user", userid);
            FormBean fb = new FormBean();
            r.setUserid(userid);
            r.show();
            return mapping.findForward(LOGGER);
        } else {
            return mapping.findForward(LOGGER);
        }
    }
}

here logincvalidate is function where u match userid and password with ur database ... this is simple action class u can use for login jsp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜