request和response对象

编程

https://how2j.cn/k/struts/struts-request-response/63.html#nowhere

 

 

package

 

com.how2java.action;

 

import

 

java.util.Map;

 

import

 

javax.servlet.http.HttpServletRequest;

import

 

javax.servlet.http.HttpServletResponse;

 

import

 

org.apache.struts2.ServletActionContext;

 

import

 

com.how2java.bean.Product;

import

 

com.opensymphony.xwork2.ActionContext;

import

 

com.opensymphony.xwork2.ActionSupport;

 

public

 

class

 

ProductAction 

extends

 

ActionSupport {

    

private

 

Product product;

 

    

public

 

String show() {

        

HttpServletRequest request = ServletActionContext.getRequest();

        

HttpServletResponse response = ServletActionContext.getResponse();

 

        

System.out.println(

"request: "

 

+ request);

        

System.out.println(

"response: "

 

+ response);

 

        

product = 

new

 

Product();

        

product.setName(

"iphone7"

);

        

return

 

"show"

;

    

}

 

    

public

 

String add() {

 

        

Map m = ActionContext.getContext().getSession();

        

m.put(

"name"

, product.getName());

        

return

 

"show"

;

    

}

 

    

// public void validate(){

    

// if ( product.getName().length() == 0 ){

    

// addFieldError( "product.name", "name can"t be empty" );

    

// }

    

// }

 

    

public

 

Product getProduct() {

        

return

 

product;

    

}

 

    

public

 

void

 

setProduct(Product product) {

        

this

.product = product;

    

}

}

以上是 request和response对象 的全部内容, 来源链接: utcz.com/z/513105.html

回到顶部