<%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="java.net.URLEncoder"%>
<html>
<form action="index.jsp">
<body>
First INPUT:
<input name="firstinput" type="text" name="fname">
<br>
<input type="submit" value="Submit">
<%
String first = request.getParameter("firstinput");
String Searchtext=URLDecoder.decode(first,"UTF-8");
out.println(Searchtext);
out.println(URLEncoder.encode(Searchtext,"UTF-8"));
%>
</body>
</form>
</html>
这是我的代码我想要在Jsp中编码和解码文本Actully我希望当输入文本“”,'',/ / ......任何特殊章程它应该打印相同,因为它是文本,如果输入“你好“或你好然后它应该打印你好或如果输入'你好'然后它也应该打印你好...特殊包机应该不显示请帮助我我无法做到这一点...
答案 0 :(得分:0)
我认为你需要这个:
String lWithoutSpecials = first.replaceAll("[^\\p{Alpha}]+","");
对我而言,它很有效:
String s = "\\Hello\\ \"Hello\" 'Hello'";
String lWithoutSpecials = s.replaceAll("[^\\p{Alpha}]+", "");
System.out.println(lWithoutSpecials);
输出:
HelloHelloHello