purpose of webAppRootKey? - spring-mvc

Can somebody explain this entry in web.xml ? When it has to be used and why ?
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>webapp.root</param-value>
</context-param>
Is this something related to Spring or general one?

It is both general and Spring Specific. context-param allows you to specify context parameters (that is general) but what you specify is specific to your application, and your application will look for the parameter and use it.
In this case it is the key of the system property that should specify the root directory of this web app. Applied by WebAppRootListener or Log4jConfigListener.

I had the same question, and found this page and later WebApproot in Spring.
It is best explained there in mblinn's answer.

this param is very important, in my tomcat I have two app, in order to achieve localhost/ navigates to app1 and 127.0.0.1/ navigates to app2, FYI both of their context path is / , what I do is I add another Host element to tomcat's server.xml with defaultHost name is 127.0.0.1 and appBase is parent dir of ROOT.war (app2)
hope this is useful

Related

How to disable the default Servlet in Karaf?

I am new to Karaf and I am trying to get the default servlet to stop listening:
I managed to stop all the other things which I do not need by stopping their respective bundles, but for the default servlet I am unable to figure out how to stop it.
Currently it replys:
No services have been found.
Question: where can I disable the default servlet for the root dir?
Edit: We would like to have whiteboard serve an angular site and its ressources dirctly from /. Currenlty ResourceServlet default tries to find javascript files in its bundle ressoures (not a chance...). How do we get the default Servlet to stop bothering us? :)
It is not possible to disable the default servlet. Instead a new Servlet has to be registered under the / path. This servlet will have precedence.

Get application root URL and Directory name in Symfony 2 application

I want to know the root of the application both system eg. /var/www/app/ or /app/ for the purposes of file uploads. When I upload, I believe I need the "system" directory name, for use to links in web front end, I need the "relative" path. How do I get this information?
In a previous project, I defined constants in the app*.php files (front controller)
define('APP_ROOT', __DIR__);
Wonder if theres a better way?
In any ContainerAware class you can get location of web directory by,
$this->container->get('kernel')->getRootdir().'/../web';
If the container is not available, you can use dependency injection: set %kernel.root_dir% as an argument to your class in the service configuration.

Spring MVC 3 Mapping

This may seem simple, but not yet found a solution.
How to map to my applications www.mysite.com.br/MyController instead of www.mysite.com.br/servlet-name/MyController.
Thanks
Given that you're using Tomcat, you probably need to set your context root to be the default for your server.
If your application is configured in server.xml then this means you set the path attribute on <Context> to an empty string, ie "".
<Context docBase="webapps/MyWAR" path=""></Context>
See http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
There are other ways of setting the path attribute if you're running Tomcat in an IDE, for example directly from Eclipse. In Eclipse you set the path attribute in the Modules tab on the server window.

How can I add location elements programmatically to the web config?

I have an application which creates page routes from a database. My whole site is secured with forms authentication but I need to allow unauthenticated uses to access these routes. I don't want to hard-code <location> tags for the routes in the web.config as this will negate me using a database to generate the routes.
Can anyone help?
Thanks everyone. I've found an answer here
Basically it involves creating a folder for each route and putting a web.config file in it allowing access. This approach needs to be coupled with setting RouteExistingFiles to false so that the routes don't get confused with the folders.
Rather than using strongly typed configuration classes, why not make the modifications directly in XML?
Here's an abbreviated snippet to demonstrate the concept from some code of mine that performance IIS tuning in the machine.config. The principal is the same for other XML config files though. You just need to create the appropriate XPath statements to do what you need.
XmlDocument machineConfigFile = new XmlDocument();
machineConfigFile.Load(MachineConfigPathString);
XmlNode autoConfig = machineConfigFile.SelectSingleNode(#"/configuration/system.web/processModel/#autoConfig");
autoConfig.Value = "false";
machineConfigFile.Save(MachineConfigPathString);
When saved, the XmlDocument object will preserve all other untouched document nodes. Very handy. It works great for modifying the machine.config. The only possible issue I can see is that your application will probably reset when you save your changes to the web.config. So test it out in a safe environment with a backup of your web.config just in case the reset causes any undesired outcomes!
I found this MSDN link for you. I didn't find whether you can modify the config of running server instance this way though.
Have you considered implimenting your site security in a different way? Having a portion of the site that allows unauthenticated access and a portion that does not. I am "assuming" (bad) that you are using MVC since you are describing routes - this is very easy to do with both MVC and traditional web form applications.

Is it possible to completely negate a "higher" web.config in a subfolder?

Is it possible to completely negate a web.config in a subfolder?
Obviously, I have a web.config in the root.
If I have a subfolder called "MyApp", can I write a bunch of code in there and have it run without any reference to the web.config at root? It would have its own web.config, and wouldn't even reference the "higher" web.config in root.
What I'm looking for is complete App isolation. I'd like to be able to write an app in a subfolder of an existing site, which ignores the entire web.config hierarchy above it -- the app would an island all to itself.
I know I can use the "clear" element, but is that the best way? Just put a "clear" under every top level element? Just wondering if there's another way.
Duplicate of Will a child application inherit from its parent web.config?
On the web.config file in the root directory, wrap the <system.web> element with the following element: <location path="." inheritInChildApplications="false"></location>
Check out this link for a reference:
http://www.jaylee.org/post/2008/03/Prevent-ASPNET-webconfig-inheritance-and-inheritInChildApplications-attribute.aspx
Yes, you have to clear those sections want to override. Thinking about it a bit more, this makes sense, as the only way to clear everything might make it very hard to work out what to clear it to. Clear normally resets everything, including the root web.configs in the web.configs and machine.config defined in the frameworks /config folder on your server.
Note that you'll also lose access to the /bin folder, /app_code folder, etc. This may or may not be what you want.
Whether you can create sub-applications with your host is another matter to consider as well.
No. By design for shared hosting and simplicity sake.
IIS7 changes that a little by allowing the configs to be explicitly locked/unlocked.
It sounds more like you should create a virtual directory that is another application root entirely.
I've just come across this issue in my work and my solution was to create a new website, instead of trying to nest my application under the existing website. I kept the domain mapping the same for the new application (i.e. www.mysite.com ) but changed the port number/mapping.
As a result I can use my new app on www.mysite.com:88 and didn't have to use a subdomain.
The caveat here is that my application is a web service so having to specify the port number in the URL was a possibility for me. It might not be an option for you but I thought I would post this incase it helps someone in my situation.
The <location path="." inheritInChildApplications="false"></location> solution wasn't an option for me as the inheritInChildApplications doesn't seem to exist before ASP.Net Framework 4.0?

Resources