忽略TextBox的转义字符,获得原输入值.

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/maxjove/article/details/6870949



比如说在TextBox中输入" \0\aiHPC" 此时TextBox.text 的值就是"\\0\\aiHPC" ,想要获得textBox.Text的原样输入值(没有添加转义字符)

System.Text.RegularExpressions.Regex.Unescape(textBox1.Text) 就可以得到" \0\aiHPC ".

展开阅读全文

GWT中写了textBox不能获得

01-20

下面是方法rn[code=java]rnpackage com.packtpub.gwtbook.samples.client;rnrnimport com.google.gwt.core.client.EntryPoint;rnimport com.google.gwt.core.client.GWT;rnimport com.google.gwt.event.dom.client.ClickEvent;rnimport com.google.gwt.event.dom.client.ClickHandler;rnimport com.google.gwt.user.client.Window;rnimport com.google.gwt.user.client.rpc.AsyncCallback;rnimport com.google.gwt.user.client.rpc.ServiceDefTarget;rnimport com.google.gwt.user.client.ui.Button;rnimport com.google.gwt.user.client.ui.RootPanel;rnimport com.google.gwt.user.client.ui.TextBox;rnrnpublic class Samples implements EntryPoint rnrn public void onModuleLoad() rn //创建textboxrn final TextBox primeNumber = new TextBox();rn System.out.println("得到值==="+primeNumber.getText());rn final PrimesServiceAsync primesService = (PrimesServiceAsync) GWTrn .create(PrimesService.class);rn ServiceDefTarget endpoint = (ServiceDefTarget) primesService;rn endpoint.setServiceEntryPoint(GWT.getModuleBaseURL() + "primes");rn //创建buttonrn final Button checkPrim = new Button();rn RootPanel.get().add(primeNumber); rn RootPanel.get().add(checkPrim);rn checkPrim.setText("点一次");rn //点击调动事件rn checkPrim.addClickHandler(new ClickHandler() rn public void onClick(ClickEvent event) rn // TODO Auto-generated method stubrn AsyncCallback callBack = new AsyncCallback() rn public void onFailure(Throwable caught) rn // TODO Auto-generated method stubrn Window.alert("服务出现错误");rn rn public void onSuccess(Object result) rn // TODO Auto-generated method stubrn if (((Boolean) result).booleanValue()) rn Window.alert("yes," + primeNumber.getText()rn + "是素数!");rn else rn Window.alert("no," + primeNumber.getText()rn + "不是素数!");rn rn rn ;rn //方法判断获得值是否为素数,返回值为booleanrn primesService.isPrimeNumber(Integer.parseInt(primeNumber.getText()),callBack);rn rn );rnrnrn rnrn[/code]rnrnrnrnAsync中一个接口:rnrnpublic interface PrimesServiceAsync rn public void isPrimeNumber(int numberToVerify,AsyncCallback callback);rnrnrnrn不知为什么primeNumber.getText()为什么总是为空?rnrnGWT development mode中运行报错rn[code=java]rnrn00:00:02.627 [ERROR] Uncaught exception escapedrncom.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129) at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129) at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116) at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177) at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351) at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307) at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337) at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.google.gwt.core.client.impl.Impl.apply(Impl.java) at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213) at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) at java.lang.Integer.parseInt(Integer.java:470) at java.lang.Integer.parseInt(Integer.java:499) at com.packtpub.gwtbook.samples.client.Samples$1.onClick(Samples.java:46) at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:54) at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:1) at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1) at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40) at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193) at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88) at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127) at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129) at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116) at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177) at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351) at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307) at sun.reflect.GeneratedMethodAccessor34.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337) at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at com.google.gwt.core.client.impl.Impl.apply(Impl.java) at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213) at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71) at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172) at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363) at java.lang.Thread.run(Thread.java:662)rn[/code] 论坛

没有更多推荐了,返回首页