如何从http获取String

时间:2022-04-12 12:28:05

I use this code to get integer from the http:

我使用此代码从http获取整数:

this.id = 
 Integer.parseInt(FacesContext.getCurrentInstance().
 getExternalContext().getRequestParameterMap().get("id"));

Now I need to get String from the http. Can you tell me how I can do this? In Netbeans I tested this code:

现在我需要从http获取String。你能告诉我怎么做吗?在Netbeans中我测试了这段代码:

 this.id = 
   String.parseString(FacesContext.getCurrentInstance().
   getExternalContext().getRequestParameterMap().get("id"));

But I get an error. Can you tell me what is the proper way to do this?

但是我收到了一个错误。你能告诉我这样做的正确方法是什么?

P.S The error in Netbeans:

P.S Netbeans中的错误:

cannot find symbol
  symbol:   method parseString(java.lang.String)
  location: class java.lang.String

4 个解决方案

#1


1  

Integer.parseInt takes a String as a parameter. So you just need:

Integer.parseInt将String作为参数。所以你只需要:

this.id = FacesContext.getCurrentInstance().getExternalContext().
          getRequestParameterMap().get("id");

As you don't need to parse a String to get a String (as your compiler is telling you).

因为您不需要解析String来获取String(正如编译器告诉您的那样)。

#2


1  

FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id")

already return you a String, you dont have to parse it, besides String in Java do not have method:

已经返回一个String,你不必解析它,除了Java中的String没有方法:

String.parseString(String s)   

#3


1  

I think that the .get() returns an object. So you could append .toString() instead of parse it. The upper line returns an Integer object and there you can call .toString() too. I hope this help...

我认为.get()返回一个对象。所以你可以追加.toString()而不是解析它。上面一行返回一个Integer对象,你也可以调用.toString()。我希望这有帮助......

#4


1  

The String class does not have a parseString() method. You already have a string. This should work (if this.id is in fact a String):

String类没有parseString()方法。你已经有了一个字符串。这应该工作(如果this.id实际上是一个字符串):

   this.id = 
     FacesContext.getCurrentInstance().
     getExternalContext().getRequestParameterMap().get("id");

#1


1  

Integer.parseInt takes a String as a parameter. So you just need:

Integer.parseInt将String作为参数。所以你只需要:

this.id = FacesContext.getCurrentInstance().getExternalContext().
          getRequestParameterMap().get("id");

As you don't need to parse a String to get a String (as your compiler is telling you).

因为您不需要解析String来获取String(正如编译器告诉您的那样)。

#2


1  

FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id")

already return you a String, you dont have to parse it, besides String in Java do not have method:

已经返回一个String,你不必解析它,除了Java中的String没有方法:

String.parseString(String s)   

#3


1  

I think that the .get() returns an object. So you could append .toString() instead of parse it. The upper line returns an Integer object and there you can call .toString() too. I hope this help...

我认为.get()返回一个对象。所以你可以追加.toString()而不是解析它。上面一行返回一个Integer对象,你也可以调用.toString()。我希望这有帮助......

#4


1  

The String class does not have a parseString() method. You already have a string. This should work (if this.id is in fact a String):

String类没有parseString()方法。你已经有了一个字符串。这应该工作(如果this.id实际上是一个字符串):

   this.id = 
     FacesContext.getCurrentInstance().
     getExternalContext().getRequestParameterMap().get("id");