1、中文字元的處理
//對於post方式提交的中文字元
request.setcharacterencoding("utf-8");
string name= request.getparameter("name");
//對於get方式提交的中文字元
string rawname = request.getparameter("rawname");
//對於使用iso-8859編碼(預設編碼方式傳遞過來的中文字元,分解轉化為位元組陣列
byte rawbytes = rawname.getbytes("iso-8859");
//將位元組陣列重新編碼為字串
string name2= new string(rawbytes,"utf-8");
2、過濾器filter過濾編碼,及使用者許可權的管理
@webfilter(filtername="authority",urlpatterns=,initparams=)
public class testfilter implements filter
/*** @see filter#destroy()
*/public void destroy()
/*** @see filter#dofilter(servletrequest, servletresponse, filterchain)
*/public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception else
// pass the request along the filter chain
chain.dofilter(request, response);
}/**
* @see filter#init(filterconfig)
*/public void init(filterconfig fconfig) throws servletexception
}4、區分
則執行下面向行**後列印出如下結果:
1、 system.out.println(request.getcontextpath());
列印結果:/news
2、system.out.println(request.getservletpath());
列印結果:/main/list.jsp
3、 system.out.println(request.getrequesturi());
列印結果:/news/main/list.jsp
4、 system.out.println(request.getrealpath("/"));
5、上傳等檔案的源**(通用,使用servlet3.0提供的part類)
ssh框架學習
struts cleanup org.apache.struts2.dispatcher.actioncontextcleanup sitemesh com.opensymphony.module.sitemesh.filter.pagefilter struts org.apache.struts...
SSH框架整合的學習總結
各個配置檔案 1.配置好資料庫連線需要的bean org.hibernate.dialect.mysqldialect true true update thread 注意一定要導好jar包,同時要對應好所使用的jar包中的類 這個org.springframework.orm.hibernate3...
SSH框架流程說明(SSH框架各框架整合說明)
1.struts2和spring整合 沒有使用整合框架的時候,action請求是由struts2框架建立,當struts2和spring進行整合時,struts2框架提供了struts2 spring plugin 2.3.24.1.jar包,將建立action的操作交給了spring管理,spri...