Spring MVC 3 Mapping - spring-mvc

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.

Related

Changes in DD (init-param, context-param) reflecting in Tomcat without re-deploying

I am following headfirst JSP and Servlets book these days and it says that ServletConfig object is only created once during the life cycle of a servlet before being passed down to the init method of the servlet.
I was testing out some examples given in the book to just print out the init-params and context-params defined in the DD of my webapp using the out.println method of HttpServletResponse.
What I am seeing this is if I make any change in the DD (adding or changing param names, values) and reload the URL in my chrome browser pointing to that particular servlet inside the webapp it gets updated with the newly added params. This should not be the case. I am not redeploying the servlet (by stopping and re-running the tomcat service again) which will cause the ServletConfig object to be recreated. What is happening here?
I am running this on tomcat9 over windows 8 while the book refers to tomcat5. Has there been changes since to dynamically update the ServletConfig and Context init params? I couldn't see anything indicating this on the internet.
Look at the Tomcat logs and you 'll see the app being re-deployed.
By default changes to web.xml will trigger an application redeployment. The check for modifications happens every 10-15 seconds (I forget exactly how often).
This is the default behavior where tomcat automatically re-deploys the application
when /WEB-INF/web.xml file is updated.
As per the documentation at
http://tomcat.apache.org/tomcat-9.0-doc/deployer-howto.html#Deploying_on_a_running_Tomcat_server :
"If the Host autoDeploy attribute is "true", the Host will attempt to deploy and update web applications dynamically, as needed, for example if a new .WAR is dropped into the appBase. For this to work, the Host needs to have background processing enabled which is the default configuration.
autoDeploy set to "true" and a running Tomcat allows for:
Re-loading of a web application if the /WEB-INF/web.xml file (or any other resource defined as a WatchedResource) is updated."
To bypass the default behavior set autoDeploy to false and restart the tomcat.
You can update the server.xml to set autoDeploy to false value.The file located at
$CATALINA_BASE/conf. Tag name is Host as given below
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
I can only update the "server.xml" file, although the documentation says : In earlier versions of Tomcat the content of a Context Descriptor configuration was often stored within Tomcat's primary configuration file server.xml but this is now discouraged (although it currently still works).
So in answer to your query , no there has been no change with respect to setting autoDeploy to true or false as per the documentations of tomcat 5.x.x and tomcat 9.x.x. I am also running tomcat 9.x.x as I verify this default behavior by setting autoDeploy to false .

eclipse and websphere 8.0 - cannot change the context root

I have the IBM plugin for eclipse that allows me to develop on websphere 8.0 servers. I'm using eclipse (Juno Build).
Normally, in the project explorer, I can change the context root of an application simply by right-clicking >> properties >> Web Project Settings >> and setting the context root right there. I can literally set that context root to anything, and it doesn't change anything about it. When I check the admin console, it displays as being 'AppName', rather than anything I've set in the web project settings. That and I'm unable to change it right there in the console, since the only button I can click is "cancel". All the text fields are there for me to change it, but there's no save button anywhere...
Has anyone else had this issue? What did you do to fix it, if at all?
There are 2 places you can set a Context Root in WebSphere.
The first is in the module definition inside the application.xml file of the EAR (That file is not mandatory in WAS 8 but it is possible to use it)
The second is in the ibm-web-ext.xml file inside the WAR.
Is it important to keep in mind the application.xml settings override the ibm-web-ext.xml settings.
When you set the context root in the UI it is setting the ibm-web-ext.xml file, if you got another definition in application.xml you will see no change, as you experiencing.
My suggestion is, if you are using application.xml always set the context root there.

Creating .NET 3.0 sub-applications within .NET 1.1 applications in IIS/ASP.Net

I am basically trying to do the same thing as this question,
create a new application within a folder so it could be accessed as follows.
* http://www.domain.com/ < Main App
* http://www.domain.com/newapp < New App
The problem is that newapp is reading the web.config from the Main App, which is causing errors because it doesn't have all the same dlls etc.
For New App, in IIS, the starting point is set at /newapp, so I am not sure why it is reading the web.config from / at all. It is set as it's own application.
I am testing this in IIS6 on XP Pro, so not sure if that makes a difference.
The Main App is dotnet 1.1, and New App is 3.0.
Edit:
Adding 'inheritInChildApplications to <location> doesn't work in 1.1, you get an error:
Parser Error Message: Unrecognized attribute 'inheritInChildApplications'
This is by design. Web.config is read from the root to the app folder in question. All changes in the root apply through to your app unless your app changes it. Read this MSDN link to get a better understanding of Web.config hierarchy & inheritance.
In order to have your app ignore settings in the root you need to apply the location element with the inheritInChildApplications attribute set to false for the path.
Something like:
<location path="." inheritInChildApplications="false">
<settings.....>
</location
For example, if you have a section in the root web.config that is specific to the root app only, then wrap the location element around that section. Use the path of "." to indicate you want all items in the path below this app folder to NOT inherit this section.
As has been said - the inheritInChildApplications doesn't work in .net 1.1.
I have been doing a lot of research in this area and I originally landed here looking for solutions. The subject doesn't make it clear that this is a 1.1 targeted question.
If you are having problems and your apps are 2.0 or above then check out this article for a lot of detailed information information on the inheritInChildApplications attribute:
SOLVED: Breaking parent web.config dependencies in sub applications

purpose of webAppRootKey?

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

Read a web.config file in a virtual directory

I have an ASP.NET application (Root Application) that has a virtual directory set up to another ASP.NET application (Virtual Application). How can I make the Virtual Application read values from the Root Application's web.config file? I was looking at the WebConfigurationManager.OpenWebConfiguration() class, but I'm unsure how how to tell it to go up one level from the root. For example, I would tell it to go to ~/web.config to get the the Virtual Application's web.config file, but I need it to go up one more level to the Root Application's file structure. Is this even the correct approach?
Any help would be greatly appreciated!!
You can use the ExeConfigurationFileMap class with ConfigurationManager, like:
string configFile = new FileInfo(Server.MapPath("/Web.config")).Directory.Parent.FullName + "\\Web.config";
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = configFile;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
Response.Write(config.AppSettings.Settings["Test"].Value);
IIS does have programmatic access to its configuration data (which is documented on MSDN and/or Technet). This will be the only supported route (i.e. will continue to work across IIS versions).
Otherwise you can hack a solution (both of these will require higher than usual rights for the process):
Parse the output from appcmd.exe:
E.g. here:
> C:\Windows\system32\inetsrv\appcmd.exe list vdir
VDIR "Default Web Site/" (physicalPath:E:\Dev\weblocal\XYZ)
VDIR "Default Web Site/DevRoot/TestWebClient" (physicalPath:E:\Dev\Tests\ClientSideWeb)
VDIR "Default Web Site/Home" (physicalPath:E:\Data\Homepages)
Read the configuration directly from C:\Windows\System32\inetsrv\config.
I think you will find that your desired behavior is in fact the default behavior.
web.config settings cascade down. Your app will look up to the next hierarchical web.config if it can't find the value.
This would allow you to just look up via AppSettings etc. for most cases.
I'm not sure what happens if you really need to direct access to the file as opposed to the various config api access methods.
I have a setup like this right now using IIS7 with multiple virtual apps configured.
I tried HectorMac's suggestion again and it still doesn't work for me. As a result I am going to seek an alternative to storing my value in the web.config file.

Resources