2

This is my code in html file:

<form name="f" action="j_spring_security_check" method="post">
<input class="btn" type="button" onclick="submitForm()" value="ورود" id="submitButton" name="submitButton" disabled="disabled"/>

<input type="text" id="browser_version" name="browser_version" />
<br />
<input type="text" id="browser_type" name="browser_type"/>


 <script type="text/javascript">
    $("#submitButton").click(function() {

        var browser_version = $("#browser_version").val();
        var browser_type = $("#browser_type").val();

         alert(" browser_version   :    " + browser_version);
         alert(" browser_type   :    " + browser_type);

        $.ajax({
            type: "POST",
            url: "j_spring_security_check",
            data:'browser_version=' +encodeURIComponent(browser_version) &'browser_type=' + encodeURIComponent(browser_type),
            dataType: "json"
        }); 
    });
</script>
</form>

I used ajax jquery in this code. How to show 2 values in to java class for insert to file. For Example:

System.out.println((browser_version) or (browser_type))

If possible with an example.

nempoBu4
  • 6,191
  • 8
  • 33
  • 38
Mohammad
  • 55
  • 2
  • 7
  • There are several related Q/As here: [How to use Servlets and Ajax](http://stackoverflow.com/q/4112686/1065197) [Simple Calculator in JSP](http://stackoverflow.com/q/4114742/1065197) [calling a servlet from javascript](http://stackoverflow.com/q/3028490/1065197) [Read JSON String in Servlet](http://stackoverflow.com/q/5338943/1065197) – Luiggi Mendoza Jan 21 '15 at 05:50

2 Answers2

0
 data: {
     "browser_version": encodeURIComponent(browser_version),
     "browser_type" : encodeURIComponent(browser_type)
 },
t3chb0t
  • 11,726
  • 9
  • 65
  • 96
Nimesh
  • 744
  • 3
  • 8
  • 18
0

Assuming j_spring_security_check refers to a Servlet, here is an example of what the code would look like in your servlet class:

public class MyServlet implements javax.servlet.Servlet
{
    public void service(javax.servlet.ServletRequest req, ServletResponse res)
         throws ServletException, java.io.IOException
    {
        String browserVersion = req.getParameter("browser_version");
        String browserType = req.getParameter("browser_type");

        // use the variables browserVersion and browserType
    }

    // other methods in the servlet
}
gknicker
  • 5,321
  • 2
  • 19
  • 37