CSS text-transform not sending upper case to Busin

2020-07-23 06:54发布

问题:

I created a simple markup such as this.

<html>
    <head>
    <head>
    <body>
        <input type="text" style="text-transform:uppercase" />
    </body>
</html>

I was assuming that the browser will capitalize all inputs and indeed it was transformed

In my business layer, I am assuming that browser will send the form data on Upper case format also when I perform Post Method.

My problem is, when I receive the data at my Spring Controller, its not capitalize and I need to perform the capitalization myself.

Any idea?

回答1:

text-transform:uppercase is not converting a string to uppercase you need to do that at the server side. You can see that if you copy a transformed text via cmd-c (strg-c) and paste it to a text document. The Text will be lowercase.

Take a look: http://static.springsource.org/spring/docs/1.1.5/api/org/springframework/util/StringUtils.html#capitalize%28java.lang.String%29

Hope you are using the Spring-Framework.



回答2:

CSS only affects the presentation. The text sent is still in lowercase. You do need to uppercase the string on the server side.



回答3:

Copy the following code in your JS file:

// This function is used to change lower to upper case for the Input text
function cUpper(cObj)
{
cObj.value=cObj.value.toUpperCase();
}

After this, in your textbox's OnKeyup event put this:

return cUpper(this);

Save, upload and try.



回答4:

You also could transform it on client side using js.



回答5:

In your case I probably try to write own PropertyEditors.

See for details: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/validation.html

HTH