使用 GET 方法读取表单数据
来源:互联网 发布:淘宝怎么样做爆款 编辑:程序博客网 时间:2024/05/16 08:10
HelloForm源码:
package firstweb;// 导入必需的 java 库import java.io.*;import javax.servlet.*;import javax.servlet.http.*;// 扩展 HttpServlet 类public class HelloForm extends HttpServlet {public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {// 设置响应内容类型response.setContentType("text/html;charset=utf-8");PrintWriter out = response.getWriter();String title = "使用 GET 方法读取表单数据";String docType = "<!doctype html public \"-//w3c//dtd html 4.0 "+ "transitional//en\">\n";out.println(docType + "<html>\n" + "<head><title>" + title+ "</title></head>\n" + "<body bgcolor=\"#f0f0f0\">\n"+ "<h1 align=\"center\">" + title + "</h1>\n" + "<ul>\n"+ " <li><b>名字</b>:" + request.getParameter("first_name")+ "\n" + " <li><b>姓氏</b>:" + request.getParameter("last_name")+ "\n" + "</ul>\n" + "</body></html>");}}
web.xml源码:
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><servlet><servlet-name>helloServlet</servlet-name><servlet-class>firstweb.HelloServlet</servlet-class></servlet><servlet><servlet-name>HelloWorld</servlet-name><servlet-class>firstweb.HelloWorld</servlet-class></servlet><servlet> <servlet-name>HelloForm</servlet-name> <servlet-class>firstweb.HelloForm</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloForm</servlet-name> <url-pattern>/HelloForm</url-pattern> </servlet-mapping><servlet-mapping><servlet-name>helloServlet</servlet-name><url-pattern>/sayHi</url-pattern></servlet-mapping><servlet-mapping><servlet-name>HelloWorld</servlet-name><url-pattern>/HelloWorld</url-pattern></servlet-mapping></web-app>
静态页面:
<html><body><form action="HelloForm" method="GET">名字:<input type="text" name="first_name"> <br /> 姓氏:<inputtype="text" name="last_name" /> <input type="submit" value="提交" /></form></body></html>
通过浏览器输入测试:
http://localhost:8080/Servlet/hello.htm
效果:
0 0
- 使用 GET 方法读取表单数据
- Android 使用Post与Get方法进行表单提交数据
- 使用ifstream::get()方法从文本文件中读取数据
- 使用Http的Get方法读取网络数据
- 使用 Servlet 读取表单数据
- Java使用HTTP的get方法读取网络数据、使用post方法与网络交互通信
- jsp数据库基础之---使用post和get方法获取表单数据
- 使用get方法传递数据
- JAVA:使用HTTP的get()方法来实现网络数据的读取
- Servlet 读取表单数据
- JSP 读取表单数据
- Servlet 读取表单数据
- 使用get方法提交form表单时出现乱码解决方法
- 使用get方法提交form表单时出现乱码解决方法
- 使用get方法提交form表单时出现乱码解决方法
- servlet_05 servlet使用表单的GET方法实例
- servlet表单处理使用GET()方法实例 及复选框
- Get-Dbf through Powershell 使用Powershell读取DBF数据
- 郑州大学linux安装锐捷客户端
- Python模块学习——win32模块
- Native Camera和OpenGL ES的混合使用
- Android事件处理第一节(View对Touch事件的处理)
- 有关C++中的一个知识点
- 使用 GET 方法读取表单数据
- HDU - 3047 Zjnu Stadium 带权并查集
- STM32配置多个定时器同时为光电编码模式的注意事项
- JSTL和EL表达式
- IOS 视图View的bounds和Frame区别
- C/C++时间处理相关函数
- C++ primer plus(第六版)学习笔记、习题答案(5)
- unity3d 4.0 编译android apk出错 no platform found!
- NSProxy的使用