ServletContext中的方法

2021-07-27 06:33:46 字數 727 閱讀 9062

servletcontext介面中常用的方法:

1.void setattribute(string name,object object) 向servletcontext範圍中新增資料(map.put(key,value));

2.object getattribute(string name); 從servletcontext範圍中獲取資料(object value=map.get(key));

3.void removeattribute(string name) ;移除servletcontext範圍中的資料(map.remove(key));

二.   新建乙個實體類

user類

public class user

public void setusercode(string usercode)

public string getusername()

public void setusername(string username)

@override

public string tostring()

}2.在aservlet中

3.在bservlet中

注:servletcontext可以完成跨使用者傳遞資料。

目前填寫過得路徑:

1.超連結

2.web.xml中的url-pattern

/dosome

3.form表單的action屬性

ServletContext介面功能

使用getinitparameternames 和getinitparameter string name 來獲得web應用中的初始化引數 setattribute string name,string value 來設定共享的資料 getattribute string name 來獲得共享得資料...

ServletContext物件學習

問題 不同的使用者使用相同的資料 解決 servletcontext物件 特點 伺服器建立 使用者共享 作用域 整個專案內 生命週期 伺服器啟動到伺服器關閉 使用 獲取servletcontext物件 第一種方式 servletcontext sc this.getservletcontext 第二...

ServletContext物件的應用

servletcontext物件 user root pass 1234 1.獲取指定名稱的context配置資訊 servletcontex context this.getservletcontext string user context.getinitparameter user syste...