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

  • Home
  • SEARCH
  • 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 78721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:01:54+00:00 2026-05-10T21:01:54+00:00

I have a struts2 application with a single page that may show one of

  • 0

I have a struts2 application with a single page that may show one of a number of values stored in a database. The application is for a school with many departments and each department has many programs. The department page is accessed using a url like this

department.action?id=2 

and the DepartmentAction will load the Department with id = 2 for display. All this is fine if the user is just browsing around the site but it gets uncomfortable if I want to provide a link to say the Engineering department in the newspapers. The link will have to be http://www.myschooldomain.com/department.action?id=2. I see a number of problems with this.

First, it is not user friendly. Second, it is prone to be broken because the departments are dynamically maintained and the id for a department could change without warning making the link unstable.

I would prefer to print a url like this: http://www.myschooldomain.com/department/engineering and have that somehow go to department.action?id=2.

My thoughts so far: create an action that will parse the url for the department name at the end then look it up by name. Maybe I could add a friendlyurl field to the database for each department.

But the question is: Is there a better way to do this in struts2?

Thanks.

Update (May 2009): I just happened to stumble back over this question and thought that I would say what I did to solve it.

I created a new package in the struts.xml called departments. In this package there is only one action mapped to *. So it catches all requests to mydomain.com/departments/anything.html.

In the action class I simply parse the url and look for the part between departments/ and .html and that is the name of the department so I can do a lookup in the database for it. This has been working fine for almost 5 months now and I have implemented it for other areas of the site.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T21:01:55+00:00Added an answer on May 10, 2026 at 9:01 pm

    This is normally done by mapping a servlet to, in your case ‘/department’, and then using the path information (e.g., ‘/engineering’) within the servlet to determine the ID.

    Since the Struts2 dispatcher doesn’t implement this behavior, it might be simplest to write your own servlet. This servlet would be configured with a map of valid ‘friendly’ names to the unfriendly numeric identifiers. This could be an actual Map or it could be done with a database finder method.

    The result of getPathInfo() would be used to look up the ID, and the request would be forwarded to the department.action. Handle the null case too, which means the user is trying to browse the /departments/ directory.

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

Sidebar

Related Questions

I have a web application that uses Struts2 + Spring for the resource injection,
I have a jsp page with two radio tags. The page contains a struts2
I am building a Struts2 web application which uses tiles however I have discovered
I am developing a web application using Struts 2.1.2 and Hibernate 3.2.6.GA. I have
I'm trying to have my Struts2 app redirect to a generated URL. In this
I have a Struts (1.3x) ActionForm that has several String and boolean properties/fields, but
I'm building a Struts2 application, where data is sent to my application in a
I'm currently developing a web application using Struts2 framework. This application requires to dynamically
i am validating user input in my application using Struts2 build in validation framework
I have a working knowledge of Struts2 and Spring. I want to develop an

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.