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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:01:19+00:00 2026-06-04T08:01:19+00:00

I’m learning Spring by integrating Spring 3 into a legacy Servlet application and gradually

  • 0

I’m learning Spring by integrating Spring 3 into a legacy Servlet application and gradually converting the legacy app over.

A web.xml *-servlet.xml similar to the ones I am using are posted below. Basically things are set up such that retrieving a string like “search”, Spring will route it to a Controller and the view resolver will convert “search” into “/jsp/search.jsp”

I ran into problems doing a response.sendRedirect(“search”) from a legacy Servlet and a legacy ServletFilter To Spring. The URL came out correctly, but I got a blank page despite System.out.println() calls indicating that the JSP was reached. No error messages from Spring and the browser only told me something went wrong with the redirect.

I fixed that problem by forwarding, instead of redirecting from the legacy Servlets and ServletFilters:

request.getRequestDispatcher("search").forward(request,response);

getServletConfig().getServletContext().getRequestDispatcher("search").forward(request,response);

Going in the OTHER direction from a new JSP done in Spring 3 to a legacy Servlet, I have buttons on screens so I just used a javascript call to “location.href=/helloworld”. I will need to send some parameters, so I will likely convert those buttons into submitting tiny HTML forms.

What I am wondering is, is there a better approach to getting Spring 3 and the Legacy Servlets communicating in a better way.

Legacy Servlet => Spring 3

and

Spring 3 => Legacy Servlet

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</display-name>

  <!--welcome-file-list>
    <welcome-file>/login</welcome-file>
  </welcome-file-list-->

  <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/nsd-servlet.xml,
            /WEB-INF/nsd-security.xml
    </param-value>
  </context-param>


  <!-- Spring Security -->
  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


  <!-- Integrate A Legacy Screen Done With A Servlet -->
  <servlet>
    <servlet-name>HelloWorldServlet</servlet-name>
    <servlet-class>
            com.legacy.HelloWorldServlet
    </servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/helloworldservlet</url-pattern>
  </servlet-mapping>

</web-app>

My 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 = "/,file:/apps1/bea/user_projects/domains/acme/common/,file:/c:/weblogic_common_files/acme/"/>
  <mvc:annotation-driven/>

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


</beans>
  • 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-04T08:01:22+00:00Added an answer on June 4, 2026 at 8:01 am

    When you use response.sendRedirect(String url) you are essentially passing in a URL that you want to redirect to.

    sendRedirect observes the following rules:

    /*
    * Destination, it can be any relative or context specific path.
    * if the path starts without '/' it is interpreted as relative to the current request URI.
    * if the path starts with '/' it is interpreted as relative to the context.
    */
    
    String destination  ="/jsp/destination.jsp";        
    response.sendRedirect(response.encodeRedirectURL(destination));
    

    When you type in “search”, this is relative to the current request URI. Thus, unless your current request was to /acme/something, and assuming /acme/search is your servlet, the request will fail.

    However, if you put the path relative to the root, using /acme/search, then the request will work from any context.

    With that said, I’m not convinced this is really the best approach, as a redirect involves sending a response back to the client browser telling it to once again fetch content from yet another URL. This seems like a wasted trip to and from the server.

    A better method may be to just wire in your servlets into Spring using something like Spring MVC. It’s pretty flexible in that you can wrap new controller classes around your existing servlets and then invoke them directly by passing in the HttpServletRequest and HttpServletResponse objects. Once done, you can then slowly eliminate anything redundant with a working, efficient system instead of one chained together with redirects.

    package samples;
    
    public class SampleController extends AbstractController {
    
        private int cacheSeconds;
    
        // for wiring in cacheSeconds
        public void setCacheSeconds(int cacheSeconds) {
            this.cacheSeconds = cacheSeconds; 
        }
        public int getCacheSeconds() {
            return cacheSeconds;
        }
    
        public ModelAndView handleRequestInternal(
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
    
            // you now have a Spring Controller wired in, and you could delegate to 
              // your legacy servlet in this manner
            YourServlet servlet = new YourServlet();
    
    
            servlet.doGet(request, response);
    
            ModelAndView mav = new ModelAndView("hello");
            mav.addObject("message", "Hello World!");
            return mav;        
        }
    }
    
    <bean id="sampleController" class="samples.SampleController">
        <property name="cacheSeconds" value="120"/>
    </bean>
    

    Note that manually instantiating a servlet is not really considered a good practice or good design. Instead, this is more of a stepping stone to get your Spring Controllers wired in and connected so that you can then systematically refactor your code and eliminate the legacy servlets by moving your business logic to service layers.

    This approach jives with your plan to systematically migrate to and learn more about Spring, tackle some technical debt, all while still working on business goals related to your site.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.