Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC - passed http request argument not match the same String value, why?

I'm passing email parameter with value "[email protected] in that way:

.../confirmation?email="[email protected]"

That request is handled by following Controlerr's method which assign parameter to ModelAtrribute added to confirm.jsp view:

@RequestMapping(value="/confirmation")
    public String accessConfirmationForm(@RequestParam(value = "email") String email, Model model)
    {
        ConfirmationCode confCode = new ConfirmationCode();
        confCode.setEmail(email);
        model.addAttribute("confCode", confCode);

        return "confirm";
    }

That's code from confirm.jsp:

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page session="false" %>
<html>
<head>
<title>Confirmation</title>
</head>
<body>

<form:form modelAttribute="confCode" action="${pageContext.request.contextPath}/confirm" method="get">
<table>
<tr>
<td>Confirmation code for email ${confCode.email}:</td>
<td><form:input path="confirmationCode" /></td>
<td><font color="red"><form:errors path="confirmationCode"></form:errors></font></td>
<td><form:hidden path="email" value= "${confCode.email}" /></td>
</tr>
<tr>
<td><input type="submit" value="Confirm"></td>
</tr>
</table>
</form:form>

After submitting the form request is reirected to following controller's method:

@RequestMapping(value = "/confirm", method = RequestMethod.GET)
    public String confirmUser(
//          @RequestParam(value = "email", required=false) String email,
            @Valid @ModelAttribute(value = "confCode") ConfirmationCode confCode, BindingResult result,
            Model model) {...}

Problem is that email variable of confCode attribute in this stage is not equal to manualy type String "[email protected]", but when printing email variable on console i can see excatly the same String "[email protected]" without any trailing spaces.

It causes that email variable is not applicable when i'm trying to get by email an entity in DAO implementation class:

//it causes null reference 
Emails mail = entityManager.find(Emails.class, email);

//it returns proper Entity
Emails mail = entityManager.find(Emails.class, "[email protected]");

I think the reason why these two String aren't equal could be encoding, maybe? Encoding in my db is latin-1 (iso 8859-1)?

How to solve this problem?

Why both String aren't equal to each other?

like image 854
Kavv Avatar asked Dec 11 '25 13:12

Kavv


1 Answers

.../confirmation?email="[email protected]"

I think the param value shouldn't have double quote

like image 77
Trong Hoang Avatar answered Dec 14 '25 02:12

Trong Hoang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!