Java请求对象与响应对象!

来源:百度知道 编辑:UC知道 时间:2024/05/16 15:41:07
目前正在学Struts 请问Java中的 请求对象 和 响应对象 分别是什么意思?

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

书中提到request参数是客户请求对象!response是参数响应对象!from封装了页面传入的数据,mapping封装了页面转发的配置信息

还有就是request,response,form,mapping这4个参数的工作流程是什么或者说在public ActionForward execute这个方法中启到了什么作用?

请达人指点迷津 不胜感激!

这个是Struts1.x的版本哈!
耦合性不好!
request 在JSP中是请求对象
response 是JSP里的响应对象

form 是HTML里表单

mapping 是Form影射到Action的xml表
-------------------------------

package com.yourcompany.struts.action;

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.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.form.UserLoginForm;

public class UserLoginAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserLoginForm userLoginForm = (UserLoginForm) form;
if(userLoginForm.getUsername().equals("pujia") && userLoginForm.getPassword().equals("5400354")) return mapp