Originariamente inviato da giaste
scrivi una jsp e ti vai a prendere la servelet che tomcat ha tradotto per te!!
no niente.. ho fatto il programmino.. ho modificato un listato trovato su sto forum (era un htmledtior) e aggiunto un funzione..
codice:
import java.util.StringTokenizer;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
public class TextToServlet extends JFrame {
private String elabora(String s){
String out="";
s=s.replace("\"","\\\"");
StringTokenizer st = new StringTokenizer(s,"\n");
out = "(\"\" +";
while (st.hasMoreTokens())
out = out + "\"" + st.nextToken() +"\"+ \n";
out = out + "\"\"); ";
return out;
}
private class myDocumentListener implements DocumentListener {
public void changedUpdate(DocumentEvent de) {
editorPane.setText(elabora(codePane.getText()));
}
public void insertUpdate(DocumentEvent de) {
editorPane.setText(elabora(codePane.getText()));
}
public void removeUpdate(DocumentEvent de) {
editorPane.setText(elabora(codePane.getText()));
}
}
private JTextArea editorPane;
private JTextArea codePane;
/** Creates a new instance of TextToServlet */
public TextToServlet() {
super("HTML Editor ");
this.setSize(600,600);
this.getContentPane().setLayout(new GridLayout(2,1));
editorPane = new JTextArea();
codePane = new JTextArea();
JScrollPane upperScroll = new JScrollPane(editorPane);
JScrollPane lowerScroll = new JScrollPane(codePane);
DocumentListener documentListener = new myDocumentListener();
codePane.getDocument().addDocumentListener(documentListener);
this.getContentPane().add(upperScroll);
this.getContentPane().add(lowerScroll);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main (String[] args) {
new TextToServlet();
}
}
il problema è che vorrei mettere anche un \n a fine riga, solo che la jtextarea lo prende come a capo e quindi l'html che vede il browser è tutto su una riga..