服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

java一步一步的web编程关于servlet〈二〉


  上次说到java一步一步的web编程关于jsp与javabean
现在说servlet,由与内容多所以分几章来说
servlet〈一〉
它与别的cgi程序不同的是,它有强大的j2ee做后,配合jsp,javabean,连接ejb,
等更高一级的应用,这里慢慢说来,不同的servlet服务器配置,不同,现在就,语言本身study
这里有一些例子,先看看:

 
//hello.class
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class hello extends httpservlet {

public void doget(httpservletrequest req, httpservletresponse res)
throws servletexception, ioexception {

res.setcontenttype("text/html");
printwriter out = res.getwriter();

string name = req.getparameter("name");
out.println("<html>");
out.println("<head><title>hello, " + name + "</title></head>");
out.println("<body>");
out.println("hello, " + name);
out.println("</body></html>");
}

public string getservletinfo() {
return "a servlet that knows the name of the person to whom it's" +
"saying hello";
}
}
//helloworld.class
//-------------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class helloworld extends httpservlet {

public void doget(httpservletrequest req, httpservletresponse res)
throws servletexception, ioexception {

res.setcontenttype("text/html");
printwriter out = res.getwriter();

out.println("<html>");
out.println("<head><title>hello world</title></head>");
out.println("<body>");
out.println("<big>hello world</big>");
out.println("</body></html>");
}
}
//
------------------------
//form.html

<html>
<head>
<title>introductions</title>
</head>
<body>
<form method=get action="/servlet/hello">
if you don't mind me asking, what is your name?
<input type=text name="name"><p>
<input type=submit>
</form>
</body>
</html>
先配置一下,注意,servlet class 放在,servlets 下,访问时,servlet下访问
我这里简单放在examples下了
c:jakarta-tomcat-3.3awebappsexamplesweb-infclasses上面的class
访问的servlet class 如下
http://localhost:8080/examples/servlet/...

扫描关注微信公众号