Results 1 to 3 of 3
- 03-15-2014, 11:07 PM #1
Member
- Join Date
- Mar 2014
- Posts
- 2
- Rep Power
- 0
Get a value from an address and save it in a variable
Hello,
My name is STG and I'm new to the forum.
I just started using java because i want to create a simple web service that will take some values from within a url and save those values in variables.
To be more specific:
For my project I use the Spring Tool Suite.
I want to be able to enter a URL in a browser.. something like "localhost:8080/test?name=Root". When I hit Enter a page will be displayed showing "Hello Root" if the name in the URL is Root or "Hello User" for any other name.
I accomplish that with this code:
Java Code:String UserName = "Empty"; @RequestMapping("/test") public @ResponseBody String username(@RequestParam(value="name")String name){ if (name == "Root") UserName = "Hello" + name; else UserName = "Hello User"; return UserName; }
Java Code:<< if (name.toString() == "Root")
Can anyone help me out with this and explain me how exactly I should reform this code in order to make it work?
Thanks in advance!!!
- 03-16-2014, 12:04 AM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Get a value from an address and save it in a variable
Don't compare strings with ==. Use equals().
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 03-16-2014, 01:39 AM #3
Member
- Join Date
- Mar 2014
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Using a variable like this: setColor(variable), or how to move variables
By chronicle in forum New To JavaReplies: 2Last Post: 11-02-2013, 09:53 AM -
Make 1 Variable demand 2 things ? - (Example ; Variable=1 && 2 )
By Zertacus in forum New To JavaReplies: 2Last Post: 01-09-2013, 09:10 PM -
knowing the address of any variable or function in java
By sharod roy choudhury in forum New To JavaReplies: 3Last Post: 12-27-2012, 09:56 PM -
Dynamic variable name based on other variable
By nadissen in forum EclipseReplies: 4Last Post: 05-06-2011, 07:22 PM -
How can i save the data Internally(auto save)
By Rama Koti Reddy in forum AWT / SwingReplies: 2Last Post: 11-01-2010, 09:31 PM
Bookmarks