Yjfox.github.io

Jun Yin's Personal Blog

Follow me onGitHub

some Tips of Json & Java servlet

1-Tomcat connects derby. 2-innerHTML="". 3-replace("\'"). 4-< input checked > in Chrome


Tomcat & Derby

Need to add derbyclient.jar into library-"apache-tomcat/lib"
then code as in Glassfish, which embedded derby

String driver = "org.apache.derby.jdbc.ClientDriver";
    String url = "jdbc:derby://localhost:1527/Jun_Yin_A1_DB;create=true";
    Connection conn;
    //create JSON
    JSONObject jo;
    
    //function of Derby database connection
    protected void connectSql() {
        try {
        Class.forName(driver);
        conn = DriverManager.getConnection(url);
        }catch(Exception e) {
            System.out.println(e);
        }
    }

element.innerHTML=""

If want reset the content of a certain element, cannot just code as someelment.innerHTML="code"
Correct way is reset it as empty and then assign a new code in.

document.getElementById("brief").innerHTML="";
    
    document.getElementById("brief").innerHTML="<h3>"+JSONresp["title"]+"</h3>\n\
                                                   <h5><strong>weather: <label>"+JSONresp["weather"]+"\
                                                    </label><label id="+"time"+">"+"post on: "+JSONresp["year"]+"-"+JSONresp["month"]+"-"+JSONresp["day"]+
                                                    "</label></strong></h5><br /><blockquote><p>"+JSONresp["diary"]+"</p></blockquote>";

Replace ' before execute sql command

as "'" will end the query command. example as

String sqlexcute = "INSERT into test (title,date,weather,mood,diary) values  "
                + "('"+ title + "','" + date + "','" + weather + "','" + mood + "','" + diary + "')";

best way is using @variable query, or replace("\'","")

< input checked > in chrome

Chrome cannot display a checked input if code like this

<tr>
                   <h4>Weather:</h4>
                   <input type="checkbox" name="weather" value="sunny" checked="checked"/>Sunny
                   <input type="checkbox" name="weather" value="rain"/>Rain
                   <input type="checkbox" name="weather" value="cloud"/>Cloud
               </tr>

need to add < td >

<tr>
                   <h4>Weather:</h4>
                   <td><input type="checkbox" name="weather" value="sunny" checked="checked"/>Sunny</td>
                   <td><input type="checkbox" name="weather" value="rain"/>Rain</td>
               </tr>

end. 2014-1-20

blog comments powered by Disqus