otak info official Logo   
Personal Blog

Hariyanto Lim

정길상 / 鄭吉祥
Home   Last Posts  
Please login to see more topics and discussion categories.
goto main category list >> Software programming >> ServLet

Title : Create and define ServLet
Total Reply : 0
Total View : 2849

Total thread: 131
Total reply: 50

Post #118
Create and define ServLet
To create a new ServLet, we create a new Java class such as
', ' ', '
public class MyClass extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

// ... do some logic here


After create the .java code for the ServLet, then we must define it in web.xml
', ' ', '
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">




In the above web.xml example, we define our ServLet name as "MyServlet", the class path is "com.mydomain.mypackage.MyServLet" and then we define the servlet URL mapping using <url-pattern> to a url path "/MyServletURLpath", so when we execute this servlet in our local server we can call this servlet using "http://localhost/MyServletURLpath"
Falling in love with the world

Write : 2013-07-18 11:30:53

If you want to create a new reply then please login first.

Since 19 January 2007
Page hit : 920,930

Code update 24th June 2013
Brain is a very capable to solve big problems
but requires constant reminders about how to.
peace bird