锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
銆銆闇姹傦紝瑕佽揪鍒幫細
銆銆<select name="beanCollectionSelect" multiple="multiple" size="10">
銆銆<option value="value 0">Label 0</option>
銆銆<option value="value 1" selected="selected">Label 1</option>
銆銆<option value="value 2">Label 2</option>
銆銆<option value="value 3" selected="selected">Label 3</option>
銆銆<option value="value 4">Label 4</option>
銆銆<option value="value 5" selected="selected">Label 5</option>
銆銆<option value="value 6">Label 6</option>
銆銆<option value="value 7">Label 7</option>
銆銆<option value="value 8">Label 8</option>
銆銆<option value="value 9">Label 9</option></select>
銆銆
銆銆瑕佸疄鐜頒笂榪版晥鏋滐紝闇瑕佷袱姝ワ細
銆銆絎竴錛氳緗瓵ctionForm錛?br />銆銆涔熷垎涓ゅ皬姝ワ細絎竴灝忔蹇呴』鍦ˋctionForm涓紝鏈変竴鍙?br />銆銆private Collection beanCollection;
銆銆public Collection getBeanCollection();
銆銆
銆銆Collection beanCollection瑕佺‘淇濇槸涓涓疄鐜幫紝濡侫rrayList錛屽鏋滀笉鏄垯浼氭姤No collection found鐨勯敊璇紝Struts鐨勬渶澶т笉鏂逛究灝辨槸涓鏃﹀嚭闂錛屽畾浣嶅緢闅撅紝涓嶇煡閬撲粈涔堝湴鏂逛嬌鐢ㄩ敊璇紝鎴栧繕璁拌緗粈涔堜簡銆?br />銆銆
銆銆鍥犱負鍓嶉潰闇姹備腑option鐨剉alue鍊煎拰label鍊間笉涓鏍鳳紝閭d箞鍦╞eanCollection涓繚瀛樼殑灝辨槸涓涓獀alue鍜宭abel緇勬垚鐨勫璞★紝鍚嶄負LabelvalueBean錛屽湪LabelvalueBean涓湁涓や釜灞炴alue鍜宭abel錛?br />銆銆
銆銆鍦ㄧ▼搴忔煇涓湴鏂硅涓篵eanCollection璧嬪鹼紝濡傦細
銆銆
銆銆Vector entries = new Vector(10);銆
銆銆entries.add(new LabelvalueBean("Label 0", "value 0"));銆銆銆銆銆
銆銆entries.add(new LabelvalueBean("Label 1", "value 1"));銆銆銆銆銆
銆銆entries.add(new LabelvalueBean("Label 2", "value 2"));銆銆銆銆銆
銆銆entries.add(new LabelvalueBean("Label 3", "value 3"));銆銆銆銆銆
銆銆entries.add(new LabelvalueBean("Label 4", "value 4"));銆銆銆銆銆銆
銆銆entries.add(new LabelvalueBean("Label 5", "value 5"));銆銆銆銆銆
銆銆 entries.add(new LabelvalueBean("Label 6", "value 6"));銆銆銆銆銆銆
銆銆entries.add(new LabelvalueBean("Label 7", "value 7"));銆銆銆銆銆銆
銆銆entries.add(new LabelvalueBean("Label 8", "value 8"));銆銆銆銆銆銆
銆銆entries.add(new LabelvalueBean("Label 9", "value 9"));
銆銆
銆銆鐒跺悗鎵цsetBeanCollection(entries);
銆銆榪欐牱ActionForm涓殑beanCollection綆楁湁鍊間簡銆?br />銆銆絎簩灝忔錛岄渶瑕佽緗甋elected錛宻elected鏈変袱縐嶏紝鍗曢夊拰澶氶夛細
銆銆鍦ˋctionForm涓繀欏繪湁錛?br />銆銆
銆銆private String singleSelect = "Single 5";銆
銆銆public String getSingleSelect()
銆銆 {
銆銆銆銆銆return (this.singleSelect);
銆銆銆銆}銆
銆銆public void setSingleSelect(String singleSelect)
銆銆 {
銆銆銆銆銆this.singleSelect = singleSelect;
銆銆銆銆}
銆銆
銆銆鎴栧閫夛紝澶氶夊繀欏繪槸鏁扮粍錛?br />銆銆
銆銆private String[] beanCollectionSelect = { "value 1", "value 3",
銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆銆"value 5" };銆
銆銆public String[] getBeanCollectionSelect() {
銆銆銆 return (this.beanCollectionSelect);銆銆}
銆銆銆銆public void setBeanCollectionSelect(String beanCollectionSelect[])
銆銆 {
銆銆銆銆銆銆this.beanCollectionSelect = beanCollectionSelect;
銆銆銆銆}
銆銆
銆銆絎簩錛氬湪Jsp涓啓鍏ang lib璇彞濡備笅錛?br />銆銆
銆銆<html:select property="beanCollectionSelect" size="10" multiple="true">
銆銆銆銆銆銆<html:optionsCollection name="testbean" property="beanCollection"/>銆銆
銆銆 </html:select>
銆銆
銆銆鍏朵腑testbean鏄疉ctionForm鐨勫悕縐般?br />銆銆
銆銆浠ヤ笂鏄痟tml:options鐨凜ollection瑙e喅鏂規錛屽鏋渙ption鍊煎緢灝戯紝綆鍗曞湴鍙互瀹炵幇涓烘暟緇勶紝涓ゆ錛?br />銆銆絎竴錛氬湪ActionForm涓紝
銆銆
銆銆private String values[] =
銆銆銆銆 { "Magazine", "Journal", "News Paper","Other" };銆
銆銆private String labels[] =
銆銆銆銆 { "L-Magazine", "L-Journal", "L-News Paper","L-Other"};
銆銆銆銆private String selected = "Magazine";銆銆
銆銆public String getSelected()
銆銆{
銆銆銆銆銆return selected;
銆銆銆銆}銆銆
銆銆public void setSelected(String selected)
銆銆{
銆銆銆銆銆this.selected = selected;
銆銆銆銆}銆
銆銆public String[] getvalues()
銆銆{
銆銆銆銆銆return values;
銆銆銆銆}銆銆
銆銆public void setvalues(String[] values)
銆銆{銆銆銆this.values = values;
銆銆銆銆}銆
銆銆public String[] getLabels()
銆銆{
銆銆銆銆銆return values;
銆銆銆銆}銆銆
銆銆public void setLabels(String[] labels)
銆銆{
銆銆銆銆銆this.labels = labels;
銆銆銆銆}
銆銆
銆銆絎簩姝ュ湪jsp涓細
銆銆
銆銆<html:select property="selected" >銆銆銆銆銆
銆銆<html:options name="testbean" property="values" labelProperty="label"/>銆銆銆</html:select>
銆銆
銆銆Struts鏍囩搴撶殑浣跨敤榪樻槸闇瑕佸皬蹇冿紝涓嶅繀瀹屽叏浣跨敤Struts鐨勬爣絳懼簱錛屼釜浜烘劅瑙塖truts榪欑鏇夸唬Html璇彞鐨勬爣絳懼簱鏈変竴縐嶇壍寮洪檮浼氾紝緇欎嬌鐢ㄨ呮帉鎻″甫鏉ラ毦搴︼紝浣跨敤鑰呴櫎鐔熸倝html澶栵紝榪樺繀欏葷悊瑙truts鐨勫搴旀爣絳懼簱鐢ㄦ硶錛岃屼笖榪欑璋冭瘯鍑洪敊錛岄棶棰樹篃鏃犳硶鍑嗙‘瀹氫綅錛屾繪槸鎶借薄鍦板憡璇変綘錛宯o bean 鎴杗o form
]]>
浠g爜濡備笅錛?br />ChineseFilter.class
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ChineseFilter extends HttpServlet implements Filter {
聽private FilterConfig filterConfig;
聽聽聽聽 //Handle the passed-in FilterConfig
聽聽聽聽 public void init(FilterConfig filterConfig) throws ServletException {
聽聽聽聽聽聽聽聽 this.filterConfig = filterConfig;
聽聽聽聽 }
聽聽聽聽 //Process the request/response pair
聽聽聽聽 public void doFilter(ServletRequest request, ServletResponse response,
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 FilterChain filterChain) {
聽聽聽聽聽聽聽聽 try {
聽聽聽聽聽聽聽聽 聽
聽聽聽聽聽聽聽聽 聽String encoding=filterConfig.getInitParameter("encoding");//浠嶹EB.xml閰嶇疆鏂囦歡涓彇鍑哄弬鏁幫紝榪欐牱鎴戜滑鍙互閫氳繃閰嶇疆淇敼緙栫爜鏍煎紡錛幝犅犅犅犅犅犅犅犅犅犅犅犅犅犅犅犅犅?br />聽聽聽聽聽聽聽聽聽聽聽聽 request.setCharacterEncoding(encoding);//璁劇疆璇鋒眰鐨勭紪鐮佹牸寮?br />聽聽聽聽聽聽聽聽聽聽聽聽 filterChain.doFilter(request, response);
聽聽聽聽聽聽聽聽 } catch (ServletException sx) {
聽聽聽聽聽聽聽聽聽聽聽聽 filterConfig.getServletContext().log(sx.getMessage());
聽聽聽聽聽聽聽聽 } catch (IOException iox) {
聽聽聽聽聽聽聽聽聽聽聽聽 filterConfig.getServletContext().log(iox.getMessage());
聽聽聽聽聽聽聽聽 }
聽聽聽聽 }
聽聽聽聽 //Clean up resources
聽聽聽聽 public void destroy() {
聽聽聽聽 }
聽聽protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
聽聽聽// TODO Auto-generated method stub
聽聽聽super.doGet(arg0, arg1);聽聽
聽聽}
聽聽protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
聽聽聽// TODO Auto-generated method stub
聽聽聽super.doPost(arg0, arg1);聽聽聽
聽聽}聽
}
鍐欏畬榪囨護鍣ㄥ墿涓嬬殑灝辨槸閰嶇疆Web.xml浜?br />
聽<filter>
聽 <filter-name>ChineseFilter</filter-name>
聽 <filter-class>com.blog.filter.ChineseFilter</filter-class>
<init-param>
聽聽聽 <param-name>encoding</param-name>
聽聽聽 <param-value>GBK</param-value>銆閰嶇疆緙栫爜鏍煎紡錛屽彲浠ラ厤緗垚浣犳兂瑕佺殑緙栫爜錛圙BK,bg-2312錛?/font>
</init-param>
聽 </filter>
聽聽 <filter-mapping>
聽聽聽 <filter-name>ChineseFilter</filter-name>
聽聽聽 <url-pattern>/*</url-pattern>
聽 </filter-mapping>
濂戒簡錛岀畝鍗曠殑Filter灝卞畬鎴愪簡錛庡綋鐒朵篃鏈夌幇鎴愮殑鍖咃紝姣斿浣犵敤Struts+Spring鐨勮瘽錛岄偅Spring涓氨鏈夌幇鎴愮殑杞爜榪囨護鍣紝鎴戜滑鍙鍦╓EB錛巟ml涓厤緗竴涓嬪氨OK浜嗭紟
錛渇ilter錛?br />錛渇ilter-name錛瀍ncodingFilter錛?filter-name錛?br />聽錛渇ilter-class錛瀘rg.springframework.web.filter.CharacterEncodingFilter錛?filter-class錛?br />聽錛渋nit-param錛?br />聽錛減aram-name錛瀍ncoding錛?param-name錛?br />. 錛減aram-value錛濭BK錛?param-value錛?br />聽錛?init-param錛?br />聽錛?filter錛?br />錛渇ilter-mapping錛?br />聽錛渇ilter-name錛瀍ncodingFilter錛?filter-name錛?br />聽錛渦rl-pattern錛?*錛?url-pattern錛?br />聽錛?filter-mapping錛?br />
|
||||
![]() |
|