Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

How to handle username with space when we set to cookie? What's the best practice?

In the username, I put my Firstname and Lastname with space in between. I got an IllegalArgumentException saying cookie should not contain []. I assume it is space.

What's the best practice to handle this?

post("/sign-in", (req,resp) -> {
<String, String> model = new HashMap<>();
String username = req.queryParams("username");
resp.cookie("username", username);
model.put("username", username);
resp.redirect("/");
return null;
});

-- It will fail on resp.cookie("username", username), if I pass the username as "Firstname Lastname"

Thomas Salai
Thomas Salai
4,964 Points

Hi Doli, Can you share us your code?