java - How to escape-html in JSP before saving to database? -


I am currently learning JSP and Java and have written a very simple guest booklet to get started with JSP. But I have to make sure that no one can use CSS, so I have to get the HTML code bar before saving it in my SSQL database. I have already searched here and have found that "

  created place pStmt = conn.prepareStatment (" Enter the test values ​​(id,?,?) "); PStmt.setString (1, Request.getParameter ("sender"); PStmt.setString (2, request.getParameter ("text"); pStmt.executeUpdate ();  

So what's the proper way to do this?

Take a look at the short answer:

More detailed answers : The job of avoiding HTML is the presentation code, not the database code. What if for some reason, you Want to display data in a classic GUI like a non-web environment? You have to unexpectedly complete the whole thing, otherwise it will appear total garbage.

Just save the data in this form and make sure that you You meet the user everything right before you display it (well, numbers may not be stored as numbers, but you get this idea ).

If If you're using AJAX, you can use (or avoid Inrtekst can increase it even further R and only the strings in JavaScript).


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -