For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 4 replies, 3 voices, and was last updated 19 years, 4 months ago by
Robert Varga.
-
AuthorPosts
-
hi all
just simply what to add in the web.xml to get the serlvet instanitiated such as listenr and dispacher
suppose my servlet is simpleServlet.java
thnaks
May 28, 2006 at 8:49 pm #252699
Riyad KallaMemberMoving to OT > Soft Dev
May 29, 2006 at 7:44 am #252722@amir55 wrote:
hi all
just simply what to add in the web.xml to get the serlvet instanitiated such as listenr and dispacher
suppose my servlet is simpleServlet.java
thnaks
I use the following stuff (in Spring 1.1) for an application with Velocity as view technology:
<context-param> <param-name>defaultHtmlEscape</param-name> <param-value>true</param-value> </context-param> <filter> <filter-name>encodingFilter</filter-name> <filter-class> org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list>
You also need a placeholder index.html in the document root directory (which will not be used at all, it only needs to exist), but /index.html will be redirected according to Spring MVC controller resolution.
Best regards,
Robert
May 31, 2006 at 1:37 pm #252875thanks Robert but I could not get it to work. Look at my simple program quotes
I sent u a private message to send u my zipped programhi all
// MyServlet.java has this line
ApplicationContext ac = new FileSystemXmlApplicationContext(“src/applicationContext.xml”);// web.xml I have jsut regester to tthe servlet
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>tests.MyServlet</servlet-class>
</servlet><servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>//applicationContext.xm
is blankso the question is what to add from code to avoid many errors
many thanks to al
May 31, 2006 at 1:49 pm #252876Hi Amir,
the problem is that you want to use your own servlet which tries to load the context file from the src directory as a filesystem resource.
I recommend that you should use Spring’s own servlet and ContextListener, which provides a great deal of other features.
However, if you want to use your own servlet, then you don’t need the ContextListener, but you need at least the following two corrections (and the third is useful, too):
1. Instead of FileSystemXMLApplicationContext, use a ClassPathXMLApplicationContext.
2. Drop the src/ from the beginning of the constructor parameter. The correct value is simply “applicationContext.xml”, if you have it originally in the source directory.
3. Don’t forget to close the application context in the destroy method of the servlet.However, if you want to choose this approach, then you should be aware of the following:
– you should have this single servlet
– it should be stateless except for the context
– you should have only one instances of this servlet (specifiable in the web.xml)
– you might have integration problems with other parts of the Spring infrastructure or with examples which relies on the application context maintained in a particular place in the servlet context AND that they expect the application context to be of the type org.springframework.web.context.WebApplicationContextBest regards,
Robert
-
AuthorPosts