URL string to increase hyperlinks
Abstract: URL string to increase hyperlinks
</ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="738" border="0"> <tr> <td width = " 732 "> </ td> </ tr> </ table> ↑ Back Tags: java string, java url, String, URL
Read in the form data, and if we want to filter users to the text, to which the url string add hyperlinks, then the following code so that we can easily achieve this function, the code via jive1.4 FilterURLConverter.java, head of Finishing.
Package example;
(Public class FilterURLConverter
Private String convertURL (String input) (
/ / Check if the string is null or zero length - if so, return
/ / What was sent in.
If (input == null | | input.length () == 0) (
Return input;
)
Else (
StringBuffer buf = new StringBuffer ();
Int i = 0, j = 0, oldend = 0;
Int len = input.length ();
Char cur;
While ((i = input.indexOf ( "http://" oldend))> = 0) (
J = i +7;
Cur = input.charAt (j);
While (j <len) (
/ / Is a space?
If (cur == '') break;
/ / Is html?
If (cur == '<') break;
/ / Is a Win32 newline?
If (cur == '\ n') break;
/ / Is Unix newline?
If (cur == '\ r' & & j
J + +;
If (j
)
)
Buf.append (input.substring (oldend, i));
Buf.append ( "buf.append (input.substring (i, j));
Buf.append ( "\ ">");
Buf.append (input.substring (i, j));
Buf.append ("");
Oldend = j;
)
Buf.append (input.substring (j, len));
Return buf.toString ();
)
)
Public static void main (String args []){// test
String s = "my school home is http://10.10.l.1 OK OK";
FilterURLConverter f = new FilterURLConverter ();
System.out.println (f.convertURL (s));
)
)
The result:
C: \ java> javac FilterURLConverter.java
C: \ java> java FilterURLConverter
My school home is http://10.10.l.1 OK OK
Jsp in this test can be:
<% @ Page import = "example .*"%>
<% @ Page contentType = "text / html; gb2312 charset ="%>
<head>
</ Head>
<body>
<form Name="form1" method="post" action="">
Your Home URL address:
<input Type="text" name="url">
<input Type="submit" name="Submit" value="æäº¤">
</ Form>
<%
FilterURLConverter f = new FilterURLConverter ();
String url = request.getParameter ( "url");
If (url! = Null) (
Url = new String (url.getBytes ( "ISO8859_1"));
String filterurl = f.convertURL (url);
Out.println ( "Your home is:" + filterurl);
)
%>
</ Body>
Function TempSave (ElementID) (CommentsPersistDiv.setAttribute ( "CommentContent" document.getElementById (ElementID). Value); CommentsPersistDiv.save ( "CommentXMLStore");) function Restore (ElementID) (CommentsPersistDiv.load ( "CommentXMLStore"); document . getElementById (ElementID). CommentsPersistDiv.getAttribute value = ( "CommentContent");) </ td> </ tr> <tr>
Releated Java Articles
Comments
Leave a Reply






