对JavaJSP内置对象使用进行整理(页面传值)

1:session

一般情况下ID ,密码,用户名,企业用户名等都用session来传递数据,通常用到这些数据都是提交表单用用到

<input type="hidden" name="cust_id" value="<%=cust_id%>" />

列子:

    

        String user_id="",cust_id="",cust_name="",user_name="";
       注:最好要判空
        cust_id= session.getAttribute("SESSION_CUST_ID").toString();   
	user_id=session.getAttribute("SESSION_USER_ID").toString();  
	user_name=session.getAttribute("SESSION_USER_NAME").toString();

2:request

设置值

request.setAttribute("count",count);
request.setAttribute("iStart",iStart);

获取

      String iStart="",count="";
      注意点:接受值最好判下空。
	
	写法一:if(request.getParameter("iStart")!= null) {
		iStart=Integer.parseInt(request.getParameter("iStart"));
	}
	if(request.getParameter("count")!= null) {
		count=request.getParameter("count").toString();
	}
	写法二:	String search_code=request.getParameter("count")!=null?request.getParameter("count"):"";


你可能感兴趣的:(对JavaJSP内置对象使用进行整理(页面传值))