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 [solved] struts 2 mapping for .action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "[solved] struts 2 mapping for .action" Watch "[solved] struts 2 mapping for .action" New topic
Author

[solved] struts 2 mapping for .action

Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Can struts 2 do a mapping such as when the user goes to http://localhost:8080/tutorial
the framework fills in defaultUserChosenActionClassMapping.action so that it runs the execute method on the action class w/o going through
another page containing <META HTTP-EQUIV="Refresh" CONTENT="0;URL=classAction.action"> ?
What other alternatives are to do it like just with struts 2 if any?


Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

I couldn't understand your problem properly, but if you want to redirect from an action to another, then there is a redirect action result that you can use...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
When i first enter the app, i need to do a html refresh to not directly type classAction.action at the end of the URL.
I wondered if there's a way to do a struts 2 mapping to type in the application path localhost/app and struts would autocomplete from the mapping the classAction.action like:
http://localhost/app/classAction.action
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You could just not use the ".action" suffix, I suppose. Or just use the RESTful mapper, which in my opinion is less error-prone.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Thanks, what i want to achieve is typing http://localhost:8080/appname
and the application displaying main.jsp
so far i managed to get it work with:
http://localhost:8080/appname/main
http://localhost:8080/appname/mainAction
http://localhost:8080/appname/mainAction.action

However i can't achieve the effect with just the appname with these (with or without the result name="success"):

Do you know why, or how should they look to achieve the desired effect please?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Oh; you just want a welcome page? That's in web.xml, and has nothing to do with Struts (although you might need to make sure that forwards are also mapped to the filter--I don't recall).
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
That's exactly the problem, if i use the welcome page, the Action class associated with it doesn't run.
I need the Action class because i'm using s:property that sets some stuff in the page, and s:property doesn't work of course if the action class doesn't.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Other people are using actions as welcome files; some (all?) of them may have had to change the types of requests handled by the filter. Some servers require a physical file even if the request is served by an action. This is a server issue, not Struts.

The struts-user mailing list has had several threads about this over the years; I'd suggest starting your search there if you're not having good luck with a full-web search.
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Ah, welcome-file accepts actions, i didn't know it can, thanks! That solves my problem.
 
Don't get me started about those stupid light bulbs.
 
subject: [solved] struts 2 mapping for .action
 
Similar Threads
How to use, struts 1-- struts-config.xml and struts 2 -- struts.xml together?
diff b/w action and dynaaction
Strut state full or stateless
regard struts
Struts2 and Spring integration