Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:57:09+00:00 2026-06-11T05:57:09+00:00

This is my jsp from where I try to inser the user <%@ page

  • 0

This is my jsp from where I try to inser the user

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Add Users using ajax</title>
        <script src="/Spring3MVC/js/jquery.js"></script>
        <script type="text/javascript">
        function doAjaxPost() {
            // get the form values
            var firstName = $('#firstName').val();
            var lastName = $('#lastName').val();

            $.ajax({
                type: "POST",
                url: "/insert",
                data: "firstName=" + firstName + "&lastName=" + lastName,
                success: function(response) {
                    // we have the response
                    $('#info').html(response);
                    $('#firstName').val('');
                    $('#lastName').val('');
                },
                error: function(e) {
                    alert('Error: ' + e);
                }
            });
        }
        </script>
    </head>
    <body>
        <h1>Add Person</h1>
        <table>
            <tr><td>First Name : </td><td> <input type="text" id="firstName" name="firstName" /><br/></td></tr>
            <tr><td>Last Name : </td><td> <input type="text" id="lastName" name="lastName" /> <br/></td></tr>
            <tr><td colspan="2"><input type="button" value="Add Users" onclick="doAjaxPost()"><br/></td></tr>
            <tr><td colspan="2"><div id="info" style="color: green;"></div></td></tr>
        </table>
        <a href="/SpringMVC/search">Show All Users</a>
    </body>
</html>

And this is my controller code

@RequestMapping(value="/insert", method = RequestMethod.POST)
public String insertPerson(ModelMap model, HttpServletRequest request, HttpServletResponse response, @RequestParam("firstName") String firstName, @RequestParam("lastName") String lastName ) {
    personDao.savePerson(firstName,lastName);
    model.addAttribute("nameAdded", firstName+" "+lastName);
    return "personAdded";
}

When I click the ‘Add Users’ button, nothing happens. Can anyone please help me in fixing this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:57:10+00:00Added an answer on June 11, 2026 at 5:57 am

    You are using contextual URLs everywhere except the Ajax post.

    Should

    url: "/insert",

    maybe be

    url: "/SpringMVC/insert",

    or even better

    url: "<spring:url value='/insert' />",

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I send request from JSP I use this code <%@ page language=java contentType=text/html;
I am passing the following JSON object from a .jsp page to a java
How can I call a servlet from jsp ? But in this case, I
I need from one JSP open another JSP, and send POST parameters to this
I have this JSP code snippet: <%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=c%> <c:choose> <c:when test=${var1.properties[\Item Type\]
I have this jQuery code in my JSP page (jQuery 1.7.2) : function Header()
I have this strange behavior in my JSP page: I have two Integer variables
I am try to create a JSP page that will show all the status
am trying to read web page from java code and its fine for general
I have a problem and can't find information. I run my web-app from jsp-page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.