JAVA一步一步的WEB编程关于SERVLET〈二〉
2008-01-05 19:16:40 来源:WEB开发网核心提示:上次说到java一步一步的WEB编程关于jsp与JavaBean 现在说SERVLET,由与内容多所以分几章来说SERVLET〈一〉它与别的CGI程序不同的是,JAVA一步一步的WEB编程关于SERVLET〈二〉,它有强大的J2EE做后,配合JSP,现在就,语言本身STUDY这里有一些例子,JAVABEAN,连接EJB
上次说到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>
先配置一下,
更多精彩
赞助商链接