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.

1

2 Answers 2

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
}
Sign up to request clarification or add additional context in comments.

Comments

0
 data: {
     "browser_version": encodeURIComponent(browser_version),
     "browser_type" : encodeURIComponent(browser_type)
 },

2 Comments

A few words about what you have posted would be nice ;-]
on servlet or SpringController, these parameters are available with httpServletRequest.getParameter("browser_version"); r

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.