zoukankan      html  css  js  c++  java
  • JSP中获取TextArea中的值

    1.写这个大部分人都会,获取其中的值,但获取的时候就会出现我们不愿意看见其中的乱码问题

    今天写这个就是来解决乱码问题。下面以一个小例子来讲解

    2.

    (1)首先编写一个JSP页面,用来接收来自前端页面的输入

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     4 <html>
     5 <head>
     6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     7 <title>Insert title here</title>
     8 </head>
     9 <body>
    10     <form action="view.jsp" method = "post">
    11         <textarea rows="10" cols="30" name = "content"></textarea>
    12         <input type = "submit" value="submit"/>
    13     </form>
    14 </body>
    15 </html>
    input.jsp

    (2)编写第二个JSP页面,用来显示

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     4 <html>
     5 <head>
     6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     7 <title>Insert title here</title>
     8 </head>
     9 <body>
    10     <%
    11         request.setCharacterEncoding("UTF-8");
    12         String content = request.getParameter("content");
    13         out.println(content);
    14     %>
    15 </body>
    16 </html>
    view.jsp

    3.

    为什么这样呢,原因是当网前端浏览器提交时,要只定编码

    4.结果图

    输入图

    结果图

    好了,验证完成.

  • 相关阅读:
    使用vue自定义组件以及动态时间
    vue案列
    解决adb devices无法连接夜神模拟器
    手动解除浏览器跨域限制
    HBuilder实现WiFi调试Android
    Spring mvc文件下载
    3大框架Struts、Hibernate、Spring简单了解
    简单了解ajax
    使用本地计划任务定时关闭azure虚拟机
    调整虚拟机的尺寸
  • 原文地址:https://www.cnblogs.com/sxmcACM/p/3763054.html
Copyright © 2011-2022 走看看