servlet基础(3)
out.print("<html><head></head><body>hello world ~~mars</body></html>");
out.close();
}
/* protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter out = resp.getWriter();
out.print("<html><head></head><body>hello world ~~mars</body></html>");
out.close();
}*/
}
package com.mars;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletTest extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter out = resp.getWriter();
out.print("<html><head></head><body>hello world ~~mars</body></html>");
out.close();
}
/* protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter out = resp.getWriter();
out.print("<html><head></head><body>hello world ~~mars</body></html>");
out.close();
}*/
}
要求:
(1) 编写JSP页面,创建表单,表单中包含“文本框”及“提交”按钮
(2) 编写servlet程序,在程序中读取出用户在表单中输入的内容,并将其显示在页面上
(3) 创建servlet 程序时,可采用MyEclipse中直接new—servlet的方式
[java]
package com.mars;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletTest2 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gbk");
相关新闻>>
- 发表评论
-
- 最新评论 更多>>