How to get param value from java servlet -
I am trying to pass the absolute values for the Java Servlet, but the returned string is not correct. Consolidating the values and checking whether the key exists or not.
Map Params; Parameters = request.getParameterMap (); String id = params.get ("id"). ToString (); String data = params.get ("data"). ToString (); System.out.println (+ ID with "Streaming" + Data + "ID); However, if I use http: // localhost: 8080 / Serv / stream / data = hereisdata and ID = if you call this servicelet through my output looks like this: streaming [ljava.lang.String; @ [Ljava.lang.String; @ 36314ab8] What am I missing?
Edit: The suggested answers are not working I am covering the whole class because I have some fort in class I am growing: java.util. * Import javax.servlet.http.HttpServletRequest; import engine streamer; public class analyzer controller {private map params; personal string pathInfo; private HttpServletRequest Request; Public Analyst Controller (HTTPSArlet Request) {this.params = request.getParameterMap (); this.pathInfo = request.getPathInfo ();} Public processing with zero process () {system.out.println ("" procing + pathInfo); Switch (pathinfo) {case "/ section / data": if (Paramazo canteens ("id") and parachines canteensky ("data")) process flow (); break; }} Private Zero Process Stream () {System.out.println ("Uses to Stream"); String data = request.getParameter ("data"); String id = request.getParameter ("id"); Stream stream = new streamer (); Stream.streamInput (Data, "Analyzer", ID); }} This line is specifically throwing NPE: string data = request.getParameter ("data");
If you see the documents, then this map Type map & lt; String returns string [] & gt; . Therefore, you have returned from the map with the value string [] array. String ID = params.get ("id") must remove the element first. [0]; Of course, you can avoid all this and using the method, you can get the parameters directly from the request object.
string id = request.getParameter ("id"); Edit: By looking at your class code, it looks like the example variable request has not been initiated by the manufacturer Get started in: Public Analyst Controller (HTTPSERT request) {this.request = request; // Start your instance variable request that is used in other methods. This.params = request.getParameterMap (); This.pathInfo = request.getPathInfo (); }
Comments
Post a Comment