|
|
|
มีใครพอจะเคยเขียน JSP บ้างครับ... มันติดปัญหาตรง อัฟเดท นะครับ... |
|
|
|
|
|
|
|
Code (JavaScript)
package midterbean;
import java.util.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
public class blogs {
private int topicID;
private String tpHeader;
private String detail;
Date dater = new Date();
Date update = new Date();
SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
private dbConn conn;
public blogs() {
this.topicID = 0;
this.tpHeader = "";
this.detail = "";
this.dater = new Date();
this.update = new Date();
this.conn = new dbConn();
}
public int getTopicID() {
return topicID;
}
public void setTopicID(int topicID) {
this.topicID = topicID;
}
public String getTpHeader() {
return tpHeader;
}
public void setTpHeader(String tpHeader) {
this.tpHeader = tpHeader;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public Date getDater() {
return dater;
}
public void setDater(Date dater) {
this.dater = dater;
}
public Date getUpdate() {
return update;
}
public void setUpdate(Date update) {
this.update = update;
}
public dbConn getConn() {
return conn;
}
public void setConn(dbConn conn) {
this.conn = conn;
}
public void newTopic() {
try {
String queryInsert = "INSERT INTO topic VALUES (0,'" + tpHeader
+ "', '" + detail + "', '" + dater + "','" + update + "')";
Statement stmt = conn.getConn().createStatement();
stmt.executeUpdate(queryInsert);
conn.disconnect();
} catch (SQLException e) {
e.printStackTrace();
}
}
public ResultSet readAlltopic() {
ResultSet rs = null;
try {
String queryString = "SELECT * FROM topic ORDER BY topic_id DESC LIMIT 0,10"; //LIMIT 0,6
Statement stmt = conn.getConn().createStatement();
rs = stmt.executeQuery(queryString);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public ResultSet readTopic(String id) {
ResultSet rs = null;
try {
String queryString = "SELECT * FROM topic WHERE topic_id='"+id+"'"; //LIMIT 0,6
Statement stmt = conn.getConn().createStatement();
rs = stmt.executeQuery(queryString);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
public void delTopic(String del) throws SQLException,Exception{
try {
String sqlDel = "DELETE FROM topic WHERE topic_id='" + del + "'";
Statement stmt = conn.getConn().createStatement();
stmt.executeUpdate(sqlDel);
} catch (SQLException sqle) {
throw new SQLException("Cloud not excute query...!");
}
}
public void updateTopic(String topic) {
try {
String queryString = "UPDATE user SET tp_header='" + tpHeader
+ "', detail='" + detail + "', update='" + update
+ "' WHERE topic_id='" + topic + "'";
Statement stmt = conn.getConn().createStatement();
stmt.executeUpdate(queryString);
} catch (SQLException e) {
e.printStackTrace();
}
}
public void clearData(){
this.topicID = 0;
this.tpHeader = "";
this.detail = "";
this.dater = new Date();
this.update = new Date();
}
public void disconnect(){
conn.disconnect();
}
}
Code (PHP)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.sql.*,java.util.*,java.text.SimpleDateFormat,java.text.ParseException" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<jsp:useBean id="blogs" class="midterbean.blogs" scope="session"></jsp:useBean>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JSP simble blog...</title>
<link href="includes/public.css" media="all" rel="stylesheet" type="text/css"/>
<script language="javascript" src="includes/jscripts.js"></script>
<script type="text/javascript" src="editor/ed.js"></script>
</head>
<%
String editor = request.getParameter("edit");
%>
<body onload="blogPost();">
<center>
<table align="center" width="800px" border="0" cellspacing="0" cellpadding="0">
<tr class="frame_tr">
<td width="30" align="left" ><img src="images/frame/frame-board_01.png" width="30" height="30" /></td>
<td width="850px" class="frame_top"></td>
<td width="30" align="right"><img src="images/frame/frame-board_03.png" width="30" height="30" /></td>
</tr>
<tr>
<td align="left" class="frame_left"> </td>
<td><div class="framboder"><table width="850" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="images/header_01.jpg" width="624" height="85" border="0" /></td>
<td><img src="images/header_02.jpg" width="226" height="85" border="0" /></td>
</tr>
<tr>
<td class="hederBg" valign="bottom" style="cursor:pointer;" title="JSP Simble Blog...">
<div align="right"> <marquee align="right" width="580px" height="30px" direction="left" onmouseover="stop();" onmouseout="start();" scrolldelay="100">You have can to read and give one's opinion for JSP-Simble Blog...</marquee></div></td>
<td><img src="images/header_04.jpg" width="226" height="45" border="0" /></td>
</tr>
</table></td>
</tr>
<tr>
<td class="tb_center" align="center" valign="top"><table width="800" height="35" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="378" class="bgMenu">
<table width="350" height="35" border="0" cellpadding="0" cellspacing="3">
<tr valign="middle">
<td width="42" align="right"><img src="images/home.png" width="20" height="20" border="0" alt="Home..." title="Home..." /></td>
<td width="45"><div align="left"><a href="home.jsp"></>Home</a></div></td>
<td width="34" align="right"><img src="images/link.png" width="20" height="20" border="0" alt="Links..." title="Links..." /></td>
<td width="37"><div align="left"><a href="links.jsp">Links</a></div></td>
<td width="34" align="right"><img src="images/about.png" width="20" height="20" border="0" alt="About us..." title="About us..." /></td>
<td width="49"><div align="left"><a href="login.jsp">Login</a></div></td>
<td width="28" align="right"><img src="images/help.png" width="20" height="20" border="0" alt="Help..." title="Help..." /></td>
<td width="54"><div align="left"><a href="about_us.jsp">About</a></div></td>
</tr>
</table></td>
<td width="422" align="right">
<%@ include file="includes/userMenu.jsp" %>
</td>
</tr>
</table>
<div align="right"></div></td>
</tr>
<tr>
<td class="tb_center" align="center" valign="top">
<div align="center" class="container">
<!-- Form Blog -->
<br/><br/><br/>
<%
String tmp;
String submit;
boolean flag = false;
String msgError = "";
submit = request.getParameter("submit");
if (submit != null) {
//tmp = request.getParameter("txtHead").trim();
tmp = new String(request.getParameter("txtHead").getBytes("ISO8859_1"),"UTF-8");
System.out.println("Header : " +tmp);
if (tmp == null || tmp.length() <= 0) {
msgError += "<font color=red>กรุณาใส่หัวข้อ... <br></font>";
flag = true;
}
blogs.setTpHeader(tmp);
tmp = new String(request.getParameter("mytxtarea").getBytes("ISO8859_1"),"UTF-8");
System.out.println("Dtail : "+tmp);
if (tmp == null || tmp.length() <= 0) {
msgError += "<font color=red>กรุณาใส่ ข้อมูล... <br></font>";
flag = true;
}
blogs.setDetail(tmp);
//SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
//comm.setDater(formater);
if(flag == true){
//out.print("<center>"+msgError+"</center>");
out.print("<center><img src='images/error.png' border='0'/> กรุณาตรวจสอบข้อมูลให้ถูกต้อง...!<center>");
}else {
out.println("<div align='center' style=' width:100%;"+
"height:auto; color:blue; font-size:16px; font-family:'Lucida Sans Unicode', 'Lucida Grande', sans-serif'>"+
"<img src='images/preload.gif' width='48' height='48' border='0' /><br />"+
"กำลังบันทึกข้อมุลล รอสักครู่... <br/><br/></div>");
blogs.updateTopic(editor);
out.println("<meta http-equiv='refresh' content='4; url=blogs.jsp' >");
}
}
%>
<form action="blogs_edit.jsp" name="frmBlog" id="frmBlog" method="get" onsubmit="return chkBlog()">
<%
Class.forName("org.gjt.mm.mysql.Driver");
ResultSet rst = blogs.readTopic(editor);
/*
if(rst.getString("topic_id") != null){
response.sendRedirect("blogs.jsp");
}
*/
while(rst.next()){
if(rst.getString("topic_id") == null){
break;
}
%>
<table border="0" cellspacing="8" cellpadding="0">
<tr>
<td><div align="right">Header :</div></td>
<td><div align="left">
<input type="text" name="txtHead" id="txtHead" size="60" value="<%=rst.getString("tp_header") %>" /> <span id="errHead" class="error"></span>
</div></td>
<td>
<div align="left"></div></td>
</tr>
<tr>
<td><div align="right">Detail :</div></td>
<td><div align="left">
<!-- editor -->
<script>edToolbar('mytxtarea'); </script>
<textarea name="mytxtarea" id="mytxtarea" class="ed" onfocus="return txtPost()"><%=rst.getString("detail") %></textarea>
<!-- End editor -->
</div></td>
<td><div align="left"><span id="errBlog" class="error"></span></div></td>
</tr>
<tr>
<td> <input type="hidden" name="dater" value="2010-09-14 01:00:41" /></td>
<td><input type="submit" name="submit" id="submit" value="Submit" class="cur" />
<input type="reset" name="reset" id="reset" value="Reset" class="cur" onclick="reloadPage()"/></td>
<td> </td>
</tr>
</table>
<%
}
%>
<!-- End Form -->
</form>
</div>
<br /><br/><br/><br/></td>
</tr>
<tr>
<td bgcolor="#a0c9ec" align="center" valign="middle" height="25"><div align="center" class="footer">Copyright © 2010 powerby JSP simble blog.</div></td>
</tr>
</table>
</div></td>
<td align="right" class="frame_rigth"> </td>
</tr>
<tr>
<td height="30" align="left"><img src="images/frame/frame-board_07.png" width="30" height="30" /></td>
<td class="frame_bottom"></td>
<td align="right"><img src="images/frame/frame-board_09.png" width="30" height="30" /></td>
</tr>
</table>
</center>
</body>
</html>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2010-09-29 22:48:21 |
By :
t-monroe |
View :
2950 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ชื่อ field ไปตรงกับคำสงวน
|
|
|
|
|
Date :
2010-09-29 23:38:22 |
By :
tungman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
น่าจะไม่ใช่นะครับ ผมลองเปลี่ยนแล้วก็ยังไม่ได้...
|
|
|
|
|
Date :
2010-09-30 01:16:00 |
By :
t-monroe |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เปลี่ยนไปใช้ bind parameter หรือ prepare statement เถอะครับ
และหาคำสั่งที่ใช้ในการ display error ครับ
|
|
|
|
|
Date :
2010-09-30 06:14:32 |
By :
... |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|