• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2 and Struts 1 working well together except for one thing

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a legacy java program that was built using Struts 1 and have successfully been able to add functions to the program using Struts 2 actions. So far everything has worked beautifully.

Here is the code I added to my old web.xml file to accommodate Struts 2:



Here is another piece of my web.xml file:



This servlet is from the old part of the program (Struts 1) and will display a PDF file on the user's screen. It works fine in the old code but after adding Struts 2 functionality to my program it no longer works. The error message I get is:



To me it's amazing how the controller is able to differentiate between calls to Struts 1 actions and Struts 2 actions (no conflicts so far). I'm guessing that my problem here is with this line of code:



Could this be a conflict between Struts 1 and Struts 2? Any ideas how I can fix this? Thank you very much!








 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This servlet is from the old part of the program (Struts 1) and will display a PDF file on the user's screen.



Technically, the servlet does not involve Struts. You have a servlet-mapping that directs a particular URL to that servlet, effectively bypassing Struts.

To me it's amazing how the controller is able to differentiate between calls to Struts 1 actions and Struts 2 actions (no conflicts so far).



No magic here. You probably have a servlet-mapping that matches any url-pattern that ends some extension (.do or .action is common) to Struts 1. Your Struts 2 filter is mapped to a wildcard without an extension, so it picks up everything else. Is there a way you can restrict the Struts 2 mapping?
 
Jim Borland
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my long-time Struts 1 mapping. The application has always used "big" for its Struts 1 url-pattern extension.



I just changed my Struts 2 filter mapping url-pattern to:



and now my pdfJobFile servlet is working again. Thanks!

In summary, my problem was a Struts 2 url pattern that conflicted with my servlet's url pattern (both used wildcards). I fixed it by narrowing the scope of my Struts 2 filter mapping down from being a wildcard.

As a precaution against further conflicts, I also narrowed the scope of my servlet's pattern by taking away its wildcard. I changed that url pattern to:



and it still seems to be working okay.

May I please ask for further clarification on your statement regarding "No magic here?" I know this is true, but it seems like magic to those of us who don't understand the process. Here is my question:

Whenever there is a link in a JSP page to one of my actions, I always use the extension .big or .action to indicate whether it is a Struts 1 or Struts 2 action. But, when using an HTML form, its action attribute does not need an extension. So, how does the controller know whether to look in struts-config.xml (Struts 1) or struts.xml (Struts 2) to find that action? In my case it always works the way it should (magic?).

Thank you very much for your assistance in this matter.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it seems like magic to those of us who don't understand the process.



As Clarke said, "Any sufficiently advanced technology is indistinguishable from magic."

how does the controller know whether to look in struts-config.xml (Struts 1) or struts.xml (Struts 2) to find that action



Struts 1 and Struts 2 use different tag libraries, but in each, the "action" parameter is the name of a Struts action, not a url, so it doesn't need the extension. Or are you saying that you're using the HTML <form> tag in both instances?
 
Jim Borland
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I loved your Clarke quote. Thanks for that.

I stand corrected. My assumption was that I have been using some raw HTML form tags, but after doing a search through my code I realize this is not true. The Struts 1 code uses <html:form action= something and in Struts 2 it's <s:form action= something. So you've answered my newest question too. It comes from the two different tag libraries. Struts 1 tags look in struts-config.xml and Struts 2 tags look in struts.xml. The magic is gone!

Thanks again for your assistance!
 
reply
    Bookmark Topic Watch Topic
  • New Topic