RequestParam / User Not Found

Hello again guys, I'd like to render my data user on a template with the GET method. I made sure my page was created and my datas are persisted in my db. I tried to render my data through the email user as it's shown below and I want my URL to be like this : http://localhost:8080/[email protected] ( which works perfectly if I write this in my browser bar ) but when I want to access to my profile it return me a USer nto found, because Spring boot sees it as null
@GetMapping("/profile")
public String getUserProfile(Model model, @RequestParam(required = false) String email){

AppUser user = repo.findByEmail(email);
System.out.println("the email is :" + email);
if(user != null){
model.addAttribute("user", user);
}else{
model.addAttribute("error", "User not found");
}

return "profile";
}
@GetMapping("/profile")
public String getUserProfile(Model model, @RequestParam(required = false) String email){

AppUser user = repo.findByEmail(email);
System.out.println("the email is :" + email);
if(user != null){
model.addAttribute("user", user);
}else{
model.addAttribute("error", "User not found");
}

return "profile";
}
12 Replies
JavaBot
JavaBot4mo ago
This post has been reserved for your question.
Hey @NoSung! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Peter Rader
Peter Rader4mo ago
Does it work if you use @RequestParam(required = false, name = "email") ? The the javac-compiler miss the -parameter flag. See https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html
JavaBot
JavaBot4mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Sung
SungOP4mo ago
Unfortunately, I have tried this one, but it didn't work, it's seen as null
Peter Rader
Peter Rader4mo ago
What have you tried? The modification of the Annotation or the -parameter flag?
Sung
SungOP4mo ago
The @RequestParam(required = false, name = "email") . I'm currently looking for an article about retrieving my query parameter but I still didn't find the solution. But as I said, oddly I can get my mail if I write the whole query in my URL http://localhost:8080/[email protected] like this, then it returns the data I want
Peter Rader
Peter Rader4mo ago
But you can not get the email when you access your profile, right?
Sung
SungOP4mo ago
Well actually, I didn't build anything yet in my profile page but when I write the whole URL, it returns me the name but when I click to access to the profile page it doesn't
Sung
SungOP4mo ago
No description
Peter Rader
Peter Rader4mo ago
I do not get it. Do you have a profile-page or not? Hm, there might be a corner-case where https://localhost:8080/[email protected] might be parsed as Domain: https://test.com using the username localhost and the password 8080/profile?email=test. But this might not explain an request to the server without email-parameter Could you try to urlencode the @?
Sung
SungOP4mo ago
I have it but when I click on the profile page it returns me a user not found because the param query is null Wait we need to urlencode the special characters ? Wait no on this one I think you're wrong because if it wasn't encoded, I couldn't even get a status 200 from my URL as I showed you above
JavaBot
JavaBot4mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server