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 8081611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:47:15+00:00 2026-06-05T16:47:15+00:00

Answer: My Spring 3 Java webapp is acme. I had this for my JQuery

  • 0

Answer:


My Spring 3 Java webapp is “acme”. I had this for my JQuery call to contact the Spring 3 Java server side components:

$.post("/test_ajax",  {state:"Alaska"});

I needed to put the “context-root” ( aka the webapp name ) in the URL:

$.post("/acme/test_ajax",  {state:"Alaska"});

I’m learning Spring 3, Ajax and JQuery. I made myself a small webapp, “acme“, to learn how to connect the 3 technologies. From my logging statements it looks the handler method getAddressList() in the Controller HelloController is not getting called after the JQuery POST request.

I started off making my JQuery call as:

$.post("/test_ajax",  {state:"Alaska"});

My code is quoted below

Any clues would be much appreciated.
Thanks in advance
Steve

hello.jsp

<html>
<head>
    <title>ACME JSP</title>
    <script language = "JavaScript" src = "../acme/js/jquery-1.7.js"></script>
    <script language = "JavaScript">
    function test(){
        $("#div1").replaceWith("Text Replaced With Javascript");
        $.post("/test_ajax",  {state:"Alaska"});
    }  
    </script>
</head>
<body>
    <h1>Hello.jsp: ${message}</h1>  

    <div id = "div1">
        Original Text
    </div>

    <input type="submit" value="Test" onclick="test()" /> 

</body>
</html>

HelloController.java:

package com.acme.controller;

import javax.annotation.Resource;
import javax.servlet.http.*;

import org.springframework.stereotype.Controller;
import org.springframework.validation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;

import org.apache.log4j.Logger;

@Controller
public class HelloController {
    private static final Logger logger  = Logger.getLogger(HelloController.class);

   @RequestMapping({"/","/hello"})
    public String home(ModelMap model) {

        logger.debug("Started...");
        model.put("message","Hello From The Spring 3.1 Controller!");
        return "hello";
    }

    @RequestMapping(value = "/test_ajax", method = RequestMethod.POST)
    public @ResponseBody String getAddressList( @RequestParam(required=true) String state,
                                                ModelMap model  ) {

        logger.debug("started...");
        logger.debug("State: " + state);
        String a_string  = "Test String From Spring And Ajax!";
        return a_string;
    }

}// end class HelloController

acme-servlet.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">


  <context:component-scan base-package="com.acme.controller" />

  <mvc:resources mapping = "/**" location = "/"/>
  <mvc:annotation-driven/>

  <bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name = "prefix" value = "/jsp/"/>
    <property name = "suffix" value = ".jsp"/>
  </bean>


</beans>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app  id="WebApp_ID" version="3.0"
   xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">


  <display-name>ACME Web Application</display-name>

  <servlet>
    <servlet-name>acme</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>acme</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!-- Help Find The Spring Config Files -->
  <listener>
    <listener-class>
                  org.springframework.web.context.ContextLoaderListener
    </listener-class>
  </listener>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/acme-servlet.xml</param-value>
  </context-param>

</web-app>

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.acme</groupId>
    <artifactId>acme</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>ACME webapp</name>
    <url>http://maven.apache.org</url>

    <dependencies>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>jstl-api</artifactId>
            <version>1.2-rev-1</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.servlet.jsp</groupId>
                    <artifactId>jsp-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>jstl-impl</artifactId>
            <version>1.2</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.servlet.jsp</groupId>
                    <artifactId>jsp-api</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.servlet</groupId>
                    <artifactId>servlet-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>


        <!-- Spring 3.1.1 -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>

        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-ldap</artifactId>
            <version>3.1.0.RELEASE</version>
        </dependency>

        <!-- Jackson JSON Mapper -->
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.6.4</version>
        </dependency>

    </dependencies>



    <build>
        <finalName>acme</finalName>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

        </plugins>

    </build>
</project>
  • 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-05T16:47:19+00:00Added an answer on June 5, 2026 at 4:47 pm

    My Spring 3 Java webapp is “acme”. I had this for my JQuery call to contact the Spring 3 Java server side components:

    $.post("/test_ajax",  {state:"Alaska"});
    

    I needed to put the “context-root” ( aka the webapp name ) in the URL:

    $.post("/acme/test_ajax",  {state:"Alaska"});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hopefully someone knows the answer to this Java-Certification question: public static void main(String[] args)
I asked this in spring forums but got no answer, and I just discovered
I'm building REST web app and my server side Java code expects request body
I am using Spring MVC to develop a Java webapp. I have a setup
This question is a continuation of Java string searching ignoring accents . The answer
In his answer to this question , BlackBear suggested replacing string y = Session[key]
I want to gain more insight regarding the scale of workload a single-server Java
I know this question is a duplicate of Execute method on startup in spring
(For just multi-line strings in Java, see: Java multiline string . This question below
The Spring Framework has two similar classes: JdbcTemplate is the old, Java 1.4 class,

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.