English 中文(简体)
印瓦·塞莱特的数字格式例外
原标题:Number Format Exception in Java Servlet
  • 时间:2012-05-10 21:25:50
  •  标签:
  • java
  • web

I have made a simple servlet in Eclipse running on Tomcat server.

我正在执行一项简单的java申请,该申请通过《保护状》message=20。 服务器获得数据。 我正在使用

String name= request.getParameter("message");

穿透镜。 当我回到申请时,我能够回来。 但当我试图处理扼杀词时:

int val=Integer.parseInt(name);

页: 1 我无法说明问题是什么。 我已经从保护站获得名称变数的价值,但为什么我可以使用?

《刑法》 我使用的是:

<<>CLIENT SIDE CODE>/strong>

URL url = new URL("http://localhost:8080/DemoServer/demoservelet");

URLConnection conn = url.openConnection();

conn.setDoOutput(true);

BufferedWriter out = new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );

out.write("message=20");

http://www.ohchr.org。

String username = request.getParameter("message").toString();

int val=Integer.parseInt(username);  //get error msg on this line

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("Passed val :"+ username+username.length());


}

I am getting error on the conversion. One more thing on return I am getting a length value of 4 which also does not make any sense?

请就此帮助我。

最佳回答

你们是否试图使用GET式参数通过或PUSH型参数通过?

GET式的过路在URL等端的参数上cks:

http://localhost:8080/DemoServer/demoservelet?value=20

A URL like this can be assembled fairly easily. You only need to change your URL-creation line, and can remove the two lines related to opening a BufferedWriter:

URL url = new URL(String.format("http://localhost:8080/DemoServer/demoservelet?value=%d", 20));

采用POST式的飞机必须遵守《吉大港山区议定书》,该议定书与你迄今为止再次使用该议定书相当相似,但所有参数必须具有新的线性。 以你为例:

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));

out.writeln("message=20");

You could also use a PrintStream, which would make formatting your parameters a little easier to handle if you need to change them:

PrintStream out = new PrintStream(conn.getOutputStream());

out.printf("message=%d
", 20);

您是否使用GET型或PUSH型,这取决于您再次通过的数据类型。

问题回答

you must to check if name is a valid numbre. name.match("^-?d+$"); it returns true if it is a number

我认为,你必须把参数写成一个参数,以便作为参数加以探测。

out.write("<param name="message" value="20">");

you have the value of output name,determine the name is a number,when the debug of check values.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签