Results 1 to 1 of 1
-
How to run Spring Client in a Servlet
The following tip is an example of running the Spring Client in a Servlet.
First copy g:\spring12\spring.jar to g:\tomcat5\common\lib and start tomcat server.
Then set class path as shown below and edit the servletclient.java.
Java Code:f:\springdemo>set classpath=f:\springdemo; f:\springdemo\spring.jar; f:\springdemo\commons-logging.jar; g:\tomcat5\common\lib\servlet-api.jar f:\springdemo\servletclient.java
Java Code:import java.io.*; import org.springframework.beans.factory.*; import org.springframework.beans.factory.xml.*; import org.springframework.core.io.*; import javax.servlet.*; import javax.servlet.http.*; public class servletclient extends HttpServlet { public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException { resp.setContentType("text/html"); PrintWriter out =resp.getWriter(); String a = req.getParameter("text1"); try { System.out.println("Please wait."); Resource res = new ClassPathResource("hello.xml"); System.out.println("Resource ok"); BeanFactory factory = new XmlBeanFactory(res); System.out.println("BeanFactory ok"); hello bean1 = (hello)factory.getBean("hello"); String s = bean1.sayhello(a); out.println(s); } catch(Exception e1) { System.out.println(""+e1);} } }Then compile the servlet and copy all the class files ie., hello.class , helloimpl.class, servletclient.class and the xml file hello.xml to g:\tomcat5\webapps\root\web-inf\classes. Copy html file servletclient.htm to g:\tomcat5\webapps\root. Add entry to web.xml file.Java Code:<html> <body> <form method=post action=" http://localhost:8080/ servlet/servletclient"> <input type=text name="text1"> <input type=submit> </form> </body> </html>
Restart Tomcat server and open browser and type url as http://localhost:8080/servletclient.htm . We will get a text box and a button. Type a name and click the 'submit' button.
Similar Threads
-
How to run Client program in Swing/AWT using Spring Framework
By Java Tip in forum Spring FrameworkReplies: 0Last Post: 04-02-2008, 10:36 AM -
Client servlet help please
By heyhey in forum New To JavaReplies: 1Last Post: 11-01-2007, 05:11 PM -
servlet client help for newbie
By heyhey in forum Java ServletReplies: 0Last Post: 10-29-2007, 04:25 PM -
How to run Client program in Swing/AWT using Spring Framework
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:20 PM -
How to run Spring Client in a Servlet
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks