Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-04-2007, 11:19 PM
JavaBean's Avatar
Moderator
 
Join Date: May 2007
Posts: 1,272
JavaBean is on a distinguished road
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.

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

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);} } }
Code:
<html> <body> <form method=post action=" http://localhost:8080/ servlet/servletclient"> <input type=text name="text1"> <input type=submit> </form> </body> </html>
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.
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run Client program in Swing/AWT using Spring Framework Java Tip Spring Framework 0 04-02-2008 12:36 PM
How to run Spring Client in a Servlet Java Tip Spring Framework 0 04-02-2008 12:33 PM
Client servlet help please heyhey New To Java 1 11-01-2007 07:11 PM
servlet client help for newbie heyhey Java Servlet 0 10-29-2007 06:25 PM
How to run Client program in Swing/AWT using Spring Framework JavaBean Java Tips 0 10-04-2007 11:20 PM


All times are GMT +3. The time now is 11:31 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org