Trying to set the right URL - Struts 2 - url

I have a Struts2 app and I'm having a bit of a problem:
at the first page (index.jsp) I have a javascript line that sets the url to './admin/Search' like this:
window.location='./admin/Search';
that sends me to the login page and if I have access it will redirect me directly to the mentioned page. The problem is that, after that, all my actions keep this first namespace '/admin'. Other actions just do not have this '/admin' namespace, for example, they could have a '/users' namespace. In this cases the server can't locate the right action because it will look for /admin/myAction in the struts.xml file. It's like struts 2 doesn't change the whole namespace/action. It just replaces the action and that's it. I really need help on this guys! Thanks.

You need to change the package namespace specified in the in struts.xml files. That will help you redirect your namespace inside your application.

Related

CakePHP 2.x: How can I overwrite an URL pointing to the index page?

I'm getting this issue:
Router::connect('/',array('controller' => 'Controller','action' => 'login'));
This will show www.mysite/controller/login as the site URL
I would like to overwrite www.mysite.com/controller/login with just www.mysite.com, but still go to the login page. Does anyone know how to do it with Cake 2.x?
The behavior It's not exactly as you describe.
What the following does:
Router::connect('/',array('controller' => 'Controller','action' => 'login'));
is allow you to type www.mysite.com in your browser, and get the view that www.mysite.com/controller/login renders.
It works like an url rewrite instead of a redirect. Therefore, the above should work as expected. However, if it's not an example, try to name your controller differently, as it may cause trouble with CakePHP.
As stated by Inigo Router::connect() just connects a route/URL to a controller action. So with your defined route you should be able to goto www.mysite.com and your login action will be served (although I'm not sure that it is a good idea to have the base URL act as the login page).
It does not prevent www.mysite.com/controller/login from working as this is one of CakePHP's default routes.
To disable the default routes you need to remove this line from routes.php:-
require CAKE . 'Config' . DS . 'routes.php';
Be warned, if you remove this line you must have defined routes for all your pages in your app's routes file. This is not necessarily a bad thing, Beware the Route to Evil is a good read in regards to this.
As I used the "Auth" component I had to add in the function
beforeFilter()
of my controller this line:
$this->Auth->allow('anAction', 'anotherAction', '**login**');

Route(URL) error for each controller

I am new to ASP.Net MVC 4. I have 2 controllers
Customer
Supplier
each controller have a menu CustomerSetup and SupplierSetup.
The first visited menu is ok, e.g when i click on CustomerSetup Menu, url looks like localhost:1496/Customer/Index its ok, now when i click on Supplier Menu, url looks like localhost:1496/Customer/Supplier/Index instead of localhost:1496/Supplier/Index and below error is shown..
Server Error in '/' Application.
The resource cannot be found.
The problem is probably because you're using hand-coded URL to point to your Supplier.Index action. You better use the Url.Action() method instead:
Supplier Menu
See Documentation
I think using html helper can help:
#Html.ActionLink("Menu name(display to user)","Action_name","Controller_name")
This will take you to your desired controller action.
eg:
#Html.ActionLink("Home","Index","Home")

How to hide url in angular?

Is it possible to not using angualar routes, because if I defined an routes like:
app.config(function($routeProvider){
$routeProvider.when('/home')
})
my url will look like www.app.com/#home,
I dont want to change url, just www.app.com nice and clean, in this case how to defined template for defferent controller and how to load the template in ng-view, and how to pass url parameter?
any idea?
You cannot do that with the built-in routing mechanism because path is required for every route. However, you can use ui-router library in order to create URL-less states and navigate to them using either code or directive.
I created this plunker to demonstrate how to use ui-router to navigate among states without modifying URL.

struts2. add path to url

I'm working with struts2.
An external app calls to my app with url
http://localhost:8080/present/jsp/mi.action?cod=02021
But because of my JSP file system, my action result is in
http://localhost:8080/present/jsp/ALTE/mi.action?cod=02021
(note the difference in ALTE).
The JSP has some lines as
<%# include file="../comuns/comunCssyJs.jsp"%>
The first ../ is to go out ALTE.
If I access with first link the page is loaded but no include files are found. However, with second link there is no problem.
Does someone know what can I do? I know I can change my JSP-s dir-s, but I'd prefer to "add automatically" the ALTE path to the url. is that possible?
Thanks in advance.
Jon
Use Struts2 <s:include> tag http://struts.apache.org/2.x/docs/include.html with <s:url> tag http://struts.apache.org/2.x/docs/url.html.

Using MVC Routes as Shortcodes

We have been trying to implement shortcodes on an ASP.NET MVC web app that allow users to uniquely invoke a given article/page using an assigned short code.
For e.g.: www.mysite.com/power would map to an actual URL: www.mysite.com/Power/Home/.
I have created various routes throughout the site that map these shortcodes to various actions and controllers within the application. From a shortcode/route point of view, everything is working great.
I, however, noticed a couple of interesting things. I have hyperlinks that I use Url.Action method to generate the URL pointing pages. Many of these pages also have short codes associated with them. For e.g.: I have a link that says:
Go to Power page
This is a page that also has the previously mentioned short-code assigned to it. When I use Url.Action, I ideally expect it to create a link as /Power/Home/Index or /Power/Home, but since I also have a route constraint mapped to it, it now generates the link as /power.
Is there a way I can just use the actual link URL when generating links? I only want short-codes when I am sending out emails etc. I want the site to generate actual URLs.
This may or may not be possible, but I wanted to see if there were any ideas out there that I could use.
Anup
Index and Home are likely defined in your route table as defaults for the Action and Controller element. When you generate the Url it wont include the defaults if they aren't needed.
You could write your own Action overload or helper, which would allow you to take more direct control of the generated URL or action link. You could approach it from two different ways: 1) a helper to generate short-code specific urls and links, and/or 2) a helper to generate the full url and/or link. If Url.Action is returning the short-code version due to your routing configuration, I'd think a good place to start would be the second option, creating a helper/extension method that will generate the full url for you.
Here's how I solved this:
Instead of naming a route with short code to point to the action url, I made the route point to a different Controller action which would then redirect to the actual route that I want it to.
For e.g.: Originally I had the code "power" defined in the route table such that it would point to www.mysite.com/Power/Home.
Now instead of pointing it to that action - Index, controller - Home, area - Power, I make it resolve to: action - Power, Controller - Home, Area - ShortCode.
In the controller now, I simply do a RedirectToAction("Index", "Home", new { Area = "Power" });
This ensures that the actual links to /Power/Home do not resolve to the shortcode "power".
This is a simple fix increased the work by a little bit, but works like a charm.

Resources