I am using Spring MVC framework for writing a web application. The first step is to modify the web.xml to make entry for the dispatcher servlet.
The snippet of the web.xml which has this change:
<servlet>
<servlet-name>MediumScaleProject</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<servlet-mapping>
<servlet-name>MediumScaleProject</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
I have following questions:
1) Does this mean anything with respect to context root has to go through this servlet mapping? (assume context root for this web application is /contextroot)
2) I want to capture user details in userDetails.html; with the above arrangement it is not working, that is if I access like this: /contextroot/userDetails.html; it is giving HTTP 404 error. What is the best strategy for handling these kind of scenarios?
If you want to make a project with the use of Spring MVC framework, you will need the Model, View and Controller.
yes everything will pass through
you better start to implement the MVC-idea
Related
I've Spring MVC webapplication which starts osgi container using ServletContextListener (osgi http bridge). I am trying to deploy felix webconsole along with other bundles, bundle gets started, but I am not able to access it.
In my web.xml
Spring DispatherServlet is configured for URL '/'
Felix ProxyServlet is configured for URL '/ext/*'
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>extension</servlet-name>
<url-pattern>/ext/*</url-pattern>
</servlet-mapping>
I tried to access webconsole using "http://localhost:8080/my-app/ext/system/console" (results 503) and "http://localhost:8080/my-app/system/console" (results 404) with no luck.
Upon debugging I see that for 'ext/system/console' URL, org.apache.felix.http.proxy.DispatcherTracker.DispatcherTracker#getDispatcher() method call in ProxyServlet#service() method returns NULL.
Can anybody point me, what I am missing here ?
I have a web.xml file with (among other things) a servlet that defines an init-param to specify the contextConfigLocation, but the param-value is BLANK?
Why is the developer doing this. I can't for the life of me find anything in the documentations for Spring 3.X that tells me what effect this has.
<servlet>
<servlet-name>restservices</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
By default the DispatcherServlet will load a xml file named [servlet-name]-servlet.xml.
This is when no init-param named contextConfigLocation is defined.
However in your case there is an init-param named contextConfigLocation defined, which tells the DispatcherServlet to load nothing but only delegate to the parent context (the one loaded by the ContextLoaderListener).
So in short there is a difference between no init-param defined or an empty init-param.
See also https://jira.springsource.org/browse/SPR-4746.
it just because the developer had nothing to declare in the servlet configuration.
he had maybe defined all what he needs in the root context.
Ah. Generally, the dispatcher servlet would follow the convention of searching for servlet-name - servlet.xml to load the WebAppContext.
It might be (and this is just guess work because i dont know your config) that there already is a file restservices-servlet.xml which is
loaded using the ContextLoaderListener
Or imported in your applicationContext.xml ( or its equivalent)
Or isnt needed, because all the beans for the Controller/ViewResolver
are configured in your applicationContext.xml
Typically, the DispatcherServlet config (WebappContext) should contain the Controller/ViewResolver bean definitions.
I am trying a sample spring MVC application. My web.xml has
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
so my question is how I can call my test controller if I just type in the url
http://localhost:8080/MySpringProject/test
Where do i need to make change to call exactly this type of URL so that my test controller called. I don't know what I am asking is correct or not but my requirement is that I don't want to end my UrL with "/" or "test.htm".
Please help and thanks in advance
You usually map your dispatcher servlet to /, and then you have controllers with #RequestMapping("/foo/bar"). But if you define a servlet with a more specific url, it will get picked up.
I want my web.xml to be able to specify param-value for a init-param for a servlet using the url used at runtime. For example:
<servlet>
<servlet-name>startup</servlet-name>
<servlet-class>com.abc.xyz.WebServlet</servlet-class>
<init-param>
<param-name>productCode</param-name>
<param-value>prod1</param-value>
</init-param>
</servlet>
Now, i want the param-value to be set based on the url the user types(prod2 or prod3). Something similar to how we can specify servlet mapping based on url-pattern. Is there a way?
Note: I'm using Weblogic. If there is a way to implement this functionality from Weblogic, that's also fine.
Thanks!
I am trying to edit a website:
server : Jetty
framework : spring
index.html page is in ./web/
From this, mapping to webpages in ./web/WEB_INF/template using Servlet. We would like to add one more module in this index.html.. requests help on Servlet mapping.
A servlet is mapped in web.xml:
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.myclass.etcetera.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
It is thus accessible through http://localhost:8080/app/MyServlet
If you are using the latest version of the servlet API (3.0), you can map it using the #WebServlet annotation on the servlet itself (and of course, specify there the url-pattern on which the servlet will respond)