File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Editing struts.xml during runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Editing struts.xml during runtime" Watch "Editing struts.xml during runtime" New topic
Author

Editing struts.xml during runtime

Deepti Nelavelli
Greenhorn

Joined: Apr 06, 2009
Posts: 5
Consider a page consisting of a list of course names. Each of those are links which when clicked upon should open up a new jsp displaying information about the course. This of course is after retrieving details from an oracle table. How is the struts.xml to be modified during runtime?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Deepti Nelavelli wrote:How is the struts.xml to be modified during runtime?

You can't edit struts.xml file during application is running, you need a context reload if you did so.
Deepti Nelavelli wrote:
Consider a page consisting of a list of course names. Each of those are links which when clicked upon should open up a new
jsp displaying information about the course. This of course is after retrieving details from an oracle table.

So you're loading menu links from database, which is generally not seen as a good practice. Why don't you hardcode links into HTML/JSP pages?

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Deepti Nelavelli
Greenhorn

Joined: Apr 06, 2009
Posts: 5
Thanks for that. This is a courseware development website where people create their courses, upload content and then download it for use later, very similar to sites like moodle.com. I need to display information in this manner for a moderator to approve courses that are being created. These courses and their associated information is not known while coding and is dynamic. Is there an elegant way to provide this kind of a functionality?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

K, Lets thought about creating a separate links (action mapping in struts.xml) for each course you add, If there are 10 users who adds 10 courses each, then its hard to maintain your struts.xml, So this solution is not at all feasible, recommended and not used, never.

Usually this things are done by using course Id and names which are passed (as a URL parameters) as per the course selected by user.

Here is How:
1. User adds course -> Course saves into db with auto generated Id/code (PK) (Database)
e.g COURSE_TABLE

2. Admin retrieves courses which are not approved yet -> So it gets listed as (JSP page)
Approve Courses:
1. My Course

3. When admin clicks for approval, on above link, the "ApproveCourses' action gets called and you can do whatever you wants with course whose id is "1".

HTH

Deepti Nelavelli
Greenhorn

Joined: Apr 06, 2009
Posts: 5
That seems to be a better way to do it. I'am new to struts 2 however.How is the course_id passed as a parameter to the URL? How do you construct a query to shoot to the database from the URL parameter course_id?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Deepti Nelavelli wrote:I'am new to struts 2 however.

Me too
Deepti Nelavelli wrote:
How is the course_id passed as a parameter to the URL?

I had shown in the Link,
see "1. My Course" in previous reply.
Deepti Nelavelli wrote:
How do you construct a query to shoot to the database from the URL parameter course_id?

You looks like new to web application development, Still We can use JDBC in action class
Deepti Nelavelli
Greenhorn

Joined: Apr 06, 2009
Posts: 5
Could you please send me links of where i can find examples of passing parameters to the url in a java class? I know it is possible in a jsp. Is using servlets in struts 2 for this purpose good?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Deepti Nelavelli wrote:Could you please send me links of where i can find examples of passing parameters to the url in a java class?

http://www.exampledepot.com/egs/javax.servlet/GetReqParam.html?l=rel OR Google Servlets get URL parameters
Deepti Nelavelli wrote:
Is using servlets in struts 2 for this purpose good?

Struts action classes are noting but servlets.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Struts 2 action classes are most certainly not servlets, nor particularly similar.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

David Newton wrote:Struts 2 action classes are most certainly not servlets, nor particularly similar.

Hmm interesting, I ask my doubts regrading this in a new thread
 
wood burning stoves
 
subject: Editing struts.xml during runtime