import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;
public class index_0002ejsp_jsp extends HttpJspBase {
// begin [file="/index.jsp";from=(8,0);to=(8,66)]
// end
// begin [file="/index.jsp";from=(9,3);to=(21,0)]
//处理表单输入汉字的乱码问题
String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859_1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e){return null;}
}
// end
// begin [file="/index.jsp";from=(23,3);to=(23,36)]
String name,email,url,body,sql;
// end
static {
}
public index_0002ejsp_jsp( ) {
}
private static boolean _jspx_inited = false;
public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
String _value = null;
try {
if (_jspx_inited == false) {
synchronized (this) {
if (_jspx_inited == false) {
_jspx_init();
_jspx_inited = true;
}
}
}
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html; charset=GB2312");
pageContext = _jspxFactory.getPageContext(this, request, response,
"", true, 8192, true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
// HTML // begin [file="/index.jsp";from=(0,70);to=(1,0)]
out.write("\r\n");
// end
// begin [file="/index.jsp";from=(1,2);to=(1,41)]
request.setCharacterEncoding("gb2312");
// end
// HTML // begin [file="/index.jsp";from=(1,43);to=(8,0)]
out.write("\r\n\r\n\r\n\r\nindex\r\n\r\n\r\n");
// end
// begin [file="/index.jsp";from=(8,0);to=(8,66)]
bean.sql_data sqlbean = null;
boolean _jspx_specialsqlbean = false;
synchronized (session) {
sqlbean= (bean.sql_data)
pageContext.getAttribute("sqlbean",PageContext.SESSION_SCOPE);
if ( sqlbean == null ) {
_jspx_specialsqlbean = true;
try {
sqlbean = (bean.sql_data) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "bean.sql_data");
} catch (ClassNotFoundException exc) {
throw new InstantiationException(exc.getMessage());
} catch (Exception exc) {
throw new ServletException (" Cannot create bean of class "+"bean.sql_data", exc);
}
pageContext.setAttribute("sqlbean", sqlbean, PageContext.SESSION_SCOPE);
}
}
if(_jspx_specialsqlbean == true) {
// end
// begin [file="/index.jsp";from=(8,0);to=(8,66)]
}
// end
// HTML // begin [file="/index.jsp";from=(8,66);to=(9,0)]
out.write("\r\n");
// end
// HTML // begin [file="/index.jsp";from=(21,2);to=(23,0)]
out.write("\r\n\r\n");
// end
// HTML // begin [file="/index.jsp";from=(23,38);to=(24,0)]
out.write("\r\n");
// end
// begin [file="/index.jsp";from=(24,2);to=(48,0)]
//接收表单传递来的信息
name = request.getParameter("name");
email = request.getParameter("email");
url = request.getParameter("url");
body = request.getParameter("body");
if (name.length()==0 ||email.length()==0||body.length()==0)
{
out.println("Sorry,Please enter your name,email and body!!!");
}
else
{
//调用sqlbean中的方法将表单数据插入数据库作为一条记录
sql="insert into guestbook (name,email,url,body) values('"+name+"','"+email+"','"+url+"','"+body+"')";
//sql="insert into guestbook (name,email,url,body) values('"+getStr(name)+"','"+email+"','"+url+"','"+getStr(body)+"')";
sqlbean.executeInsert(sql);//调用sqlbean中的方法将表单数据插入数据库作为一条记录
//调用sqlbena中的方法查询数据库,将查询结果保存到结果集RScount中
ResultSet RScount = sqlbean.executeQuery("SELECT * FROM guestbook");
int i=0;
while (RScount.next())//统计记数据库中的记录个数
{
i++;
}
// end
// HTML // begin [file="/index.jsp";from=(48,2);to=(50,9)]
out.write("\r\n\r\n现在有");
// end
// begin [file="/index.jsp";from=(50,12);to=(50,15)]
out.print( i );
// end
// HTML // begin [file="/index.jsp";from=(50,17);to=(51,0)]
out.write(" 条纪录\r\n");
// end
// begin [file="/index.jsp";from=(51,2);to=(54,0)]
RScount.close();//关闭结果集
i=0;
// end
// HTML // begin [file="/index.jsp";from=(54,2);to=(56,0)]
out.write("\r\n \r\n");
// end
// begin [file="/index.jsp";from=(56,2);to=(64,0)]
ResultSet RS=sqlbean.executeQuery("SELECT * FROM guestbook");//再次查询数据库
while (RS.next())// 逐条输出数据库中的记录
{
name=RS.getString("name");//获得记录的每一个字段
email=RS.getString("email");
url=RS.getString("url");
body=RS.getString("body");
// end
// HTML // begin [file="/index.jsp";from=(64,2);to=(67,36)]
out.write("\r\n\r\n\r\n昵称:");
// end
// begin [file="/index.jsp";from=(67,39);to=(67,43)]
out.print(name);
// end
// HTML // begin [file="/index.jsp";from=(67,45);to=(70,54)]
out.write("\r\n\r\n\r\n电子邮件:
// end
// begin [file="/index.jsp";from=(70,57);to=(70,62)]
out.print(email);
// end
// HTML // begin [file="/index.jsp";from=(70,64);to=(70,66)]
out.write("\">");
// end
// begin [file="/index.jsp";from=(70,69);to=(70,74)]
out.print(email);
// end
// HTML // begin [file="/index.jsp";from=(70,76);to=(73,49)]
out.write("\r\n\r\n\r\n个人主页地址:
// end
// begin [file="/index.jsp";from=(73,52);to=(73,55)]
out.print(url);
// end
// HTML // begin [file="/index.jsp";from=(73,57);to=(73,59)]
out.write("\">");
// end
// begin [file="/index.jsp";from=(73,62);to=(73,65)]
out.print(url);
// end
// HTML // begin [file="/index.jsp";from=(73,67);to=(76,36)]
out.write("\r\n\r\n\r\n内容:");
// end
// begin [file="/index.jsp";from=(76,39);to=(76,43)]
out.print(body);
// end
// HTML // begin [file="/index.jsp";from=(76,45);to=(80,0)]
out.write("\r\n\r\n\r\n\r\n");
// end
// begin [file="/index.jsp";from=(80,2);to=(85,0)]
}
RS.close();
}
// end
// HTML // begin [file="/index.jsp";from=(85,2);to=(87,7)]
out.write("\r\n\r\n");
// end
} catch (Throwable t) {
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (pageContext != null) pageContext.handlePageException(t);
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
}
}
}