Código PHP:
<%@ page session="false" %>
<%@ page import="java.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.sql.*" %>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<%
String ThisFileName = "TextArea.jsp";
String ValueField = request.getParameter("ValueField");
if (ValueField==null) ValueField = "";
String DBSinSalto = "";
String DBConSalto = "";
String SinSalto = ValueField;
String ConSalto = ValueField.replaceAll("\\n", "<br>");
String Inserting;
out.println("</form><P>\n");
out.println("<form action=\""+ThisFileName+"\" method=post>");
out.println("<textarea name=ValueField type= textarea cols=100 rows=3>"+ValueField+"</textarea><P>");
out.println(SinSalto+"<P>");
out.println(ConSalto+"<P>");
out.println("<input type=submit name=TextArea value=\"TextArea\"> <P>\n");
out.println("</form><P>\n");
try { Class.forName("com.mysql.jdbc.Driver"); }
catch (ClassNotFoundException e) { System.out.println(e.toString()); }
Connection MyConnection = null;
Statement MyStatement = null;
ResultSet Definitions = null;
try
{
MyConnection = DriverManager.getConnection("jdbc:mysql://"+"localhost"+"/"+"MySQLDataBase","NombreUsuario","Clave");
MyStatement = MyConnection.createStatement();
Inserting = "INSERT INTO InnoDBTable VALUES(";
Inserting = Inserting+"'"+SinSalto+"',";
Inserting = Inserting+"'"+ConSalto+"');";
out.println(Inserting+"<P>");
MyStatement.executeUpdate(Inserting);
Definitions = MyStatement.executeQuery("SELECT SinSaltoField, ConSaltoField FROM InnoDBTable;");
if(Definitions.next())
{
SinSalto = Definitions.getString("SinSaltoField");
ConSalto = Definitions.getString("ConSaltoField");
DBSinSalto = Definitions.getString("SinSaltoField");
DBConSalto = Definitions.getString("ConSaltoField");
//DBSinSalto = new String (Definitions.getBytes("SinSaltoField"),"iso-8859-1");
//DBConSalto = new String (Definitions.getBytes("ConSaltoField"),"iso-8859-1");
out.println("Lectura DB: <P>");
out.println(SinSalto+"<P>");
out.println(ConSalto+"<P>");
out.println(DBSinSalto+"<P>");
out.println(DBConSalto+"<P>");
}
MyStatement.executeUpdate("DELETE FROM InnoDBTable;");
}
catch (Exception e) { out.println(e.toString()); }
try
{
FileOutputStream MyFileOutputStream = new FileOutputStream("/home/Compartido/TextArea.jsp.txt");
Writer MyWriter = new BufferedWriter(new OutputStreamWriter(MyFileOutputStream, "UTF-8"));
MyWriter.write("SinSalto\n"+SinSalto+"\n");
MyWriter.write("ConSalto\n"+ConSalto+"\n");
MyWriter.write("DBSinSalto\n"+DBSinSalto+"\n");
MyWriter.write("DBConSalto\n"+DBConSalto+"\n");
MyWriter.flush();
MyWriter.close();
}
catch (Exception e) { out.println(e.toString()); }
%>