<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.io.*"%>
<%@ page import="java.net.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%!
public 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";
}
%>
<%
if(request.getParameter("submit")!=null){
String user=null;
String email=null;
String msg=null;
user=request.getParameter("user");
email=request.getParameter("email");
msg=request.getParameter("msg");
user=getStr(user.trim());
email=getStr(email.trim());
msg=getStr(msg.trim());
String ip=request.getRemoteAddr();
String flag="1";
Date cuurTime=new Date();
SimpleDateFormat formatter=new SimpleFormar("yyyy/MM/dd a hh:mm:ss",Locale.US);
String adate=formatter.format(currTime);
if((user.length()>0) && (msg.length()>0) && (email.length()>0)
{
String url=new String();
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=liuyanben";
try
{
Class.forNmae("com.microsoft.jdbc.sqlserver.SQLServetDriver");
}
catch(java.lang.ClassNotFoundException ae)
{
System.out.print("error:"+ae.getMessage());
}
Connection con=DriverManager.getConnection(url,"sa","");
PreparedStatement prestmt=null;
String strSQL;
try
{
strSQL="insert into guestbook (Username,IP,Email,Comment,Mydate,Flag) values(?,?,?,?,?,?)";
prestmt=con.PreparedStatement(strSQL);
prestmt.setBytes(1,user.getBytes("GBK"));
prestmt.setBytes(2,ip.getBytes());
prestmt.setBytes(1,email.getBytes("GBK"));
prestmt.setBytes(1,msg.getBytes("GBK"));
prestmt.setBytes(1,adate.getBytes("GBK"));
prestmt.setBytes(1,flag.getBytes("GBK"));
prestmt.executeUpdate();
}
catch(Exception be)
{
System.out.print("be.executeQuery:"+be.getMessage());
}
con.close();
response.sendRedirect("http://172.17.9.129:8080/guestbook/index.jsp");
}
else
{
out.print("不能输入空白项!");
return;
}
}
else
{
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>填写留言</title>
</head>
<body bgcolor="ffffff">
<form method="post" action="http://172.17.9.129:8080/guestbook/addmsg.jsp">
<table border="0" cellpadding="2" width=400 align="center">
<tr>
<td nowrap width="20%"><font color="#FF6600">姓名:</font></td>
<td width="14%">
<input type="text" name=user size="8" class="form">
</td>
<td nowrap width="18%"><font color="#FF6600">电子邮件</font></td>
<td width="48%">
<input type="text" name="email" size="18" class="form">
</td>
</tr>
<tr>
<td nowrapvalign=top bordercolor="ffffff" width="20%"><font color="ffffff">留言内容</font></td>
<td colspan="3"><textarea rows=5 name="msg" cols="38" class="form"></textarea></td>
</tr>
<tr>
<td colspan="4" align="center">
<input type="submit" name="submit" value="提交留言" class="form">
<input type="reset" name="reset" value="重新填写" class="form">
</td>
</tr>
</table>
<div align="center"></div>
</form>
</body>
</html>
<%
}
%>
--------------------------------------------------------------------------------------------------------
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 22 in the jsp file: /addmsg.jsp
Generated servlet error:
D:\Tomcat 5.0\work\Catalina\localhost\guestbook\org\apache\jsp\addmsg_jsp.java:88: ')' expected
{
^
An error occurred at line: 22 in the jsp file: /addmsg.jsp
Generated servlet error:
D:\Tomcat 5.0\work\Catalina\localhost\guestbook\org\apache\jsp\addmsg_jsp.java:126: illegal start of expression
}
^
2 errors
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.0.28