JSP制作简单新闻发布求解
org.apache.jasper.JasperException: An exception occurred processing JSP page /creatNewsdb.jsp at line 107: fTitle.setTitleName(titleName);
8: fTitle.setCreator("管理员");
9: FirstLeveldbOperation dbOperation = new FirstLeveldbOperation();
10: int result = dbOperation.insertOneRecord(fTitle);
11: if(result>0){
12: request.getRequestDispatcher("success.jsp").forward(request,response);
13: }
报错是怎么回事?
public class FirstLeveldbOperation {
public int insertOneRecord(FirstLevelTitle fTitle){
int result=0;
Connection con=null;
PreparedStatement pst = null;
try{
SimpleDateFormat HMFromat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String strCurrentTime = HMFromat.format(new Date());
con = ConnectionManager.getConnection();
String sql = "insert into FirstLevelTitle values(?,?,?,?)";
pst = con.prepareStatement(sql);
pst.setInt(1, getNewId());
pst.setString(2, fTitle.getTitleName());
pst.setString(3, fTitle.getCreator());
pst.setString(4,strCurrentTime);
result = pst.executeUpdate();
}catch(Exception e){e.printStackTrace();}
finally{
ConnectionManager.closeConnection(con);
ConnectionManager.closeStatement(pst);
}
return result;
}
private int getNewId(){
int id=0;
Connection con=null;
PreparedStatement pst = null;
ResultSet rst = null;
try{
con = ConnectionManager.getConnection();
String sql = "select max(id) from FirstLevelTitle";
pst = con.prepareStatement(sql);
rst = pst.executeQuery();
if(rst.next()){
id=rst.getInt(1);
}
}catch(Exception e){e.printStackTrace();}
finally{
ConnectionManager.closeConnection(con);
ConnectionManager.closeResultSet(rst);
ConnectionManager.closeStatement(pst);
}
return id+1;
}
}
package ye;
import java.util.*;
public class FirstLevelTitle {
private int id;
private String titleName;
private String creator;
private Date creatTime;
public FirstLevelTitle(int id,String titleName,String creator,Date creatTime){
this.id = id;
this.titleName = titleName;
this.creator = creator;
this.creatTime = creatTime;
}
public FirstLevelTitle(){
}
public int getId() {
return this.id;
}
public void setId(int paramId) {
this.id = paramId;
}
public String getTitleName() {
return this.titleName;
}
public void setTitleName(String paramTitleName) {
this.titleName = paramTitleName;
}
public String getCreator() {
return this.creator;
}
public void setCreator(String paramCreator) {
this.creator = paramCreator;
}
public Date getCreatTime() {
return this.creatTime;
}
public void setCreatTime(Date paramCreatTime) {
this.creatTime = paramCreatTime;
}
}
<form name=myForm action= "creatNewsdb.jsp" method=post>
<table align=center><tr><td>
标题名:</td><td>
<input type=text name=myText size=20></td></tr>
<tr><td colspan=2 align=center>
<input type=submit name=submit value="提交">
<input type=reset name=reset value="重置"></td>
</tr>
</table>
求大侠指点。。。。。
--------------------编程问答-------------------- fTitle有4个属性,你实例化出来的只给2个属性赋值了,FirstLevelTitle里面又没有2个属性的构造方法我的想法是public FirstLevelTitle(String titleName,String creator){
this.titleName = titleName;
this.creator = creator;
}
第二种的话把strCurrentTime跟getNewId()在JSP页面调用,然后添加到FirstLevelTitle属性里去【这种是最好的,一般设计就是这样】 --------------------编程问答-------------------- memset y1 memcpy y2 return -1 y3 m_sMsgLength y4 m_sMsgCrypt y5
m_sBillTotalMoney y6 m_sResponseCode y7 m_sMsgFeeType y8
m_sMsgDateTime y9 m_sFeeType j1 m_sMsgCode j2 m_tChkField[iIterator] j3
m_sMsgFromNode j4 MsgStreamNoFieldLength j5 tOutStream j6
m_tChkField[l_iIterator] j7 m_tMsgHead j8 TimeFieldLength + DateFieldLength j9
sMsgInBuf + iMsgOffset f1 sMsgOutBuf + iMsgOffset f2
iMsgInBufLength - MsgHeadFieldLength f3 iMsgOffset += MsgTypeFieldLength f4
iMsgOffset += NodeNoFieldLength f5 iMsgOffset += FeeTypeFieldLength f6
iMsgOffset += MoneyFieldLength f7 iMsgOffset += CardTypeFieldLength f8
iMsgOffset += CallNumberFieldLength f9 iMsgOffset += LogInOutTypeFieldLength z1
iMsgOffset += ResponseCodeFieldLength z2 setMsgLength(iMsgInBufLength) z3
iMsgOffset += BillNumberFieldLength z4 return iMsgOffset z5
iMsgOffset = TMsg::encodeMsg(sMsgOutBuf) z6 int iMsgOffset = 0 z7
iMsgOffset = TMsg::decodeMsg(sMsgInBuf, iMsgInBufLength) z8
iMsgOffset += OrderNumberFieldLength z9
//Introduction:定义的消息类成员函数的实现message.C
"message.hpp""socketcomm.hpp" extern TSocketComm* g_pSocketComm;
TMsgHead::TMsgHead(){y1(y4, 0, sizeof(y4));y1(y5, 0, sizeof(y5));
y1(m_sMsgStreamNo, 0, sizeof(m_sMsgStreamNo));
y1(m_sMsgType, 0, sizeof(m_sMsgType));y1(j4, 0, sizeof(j4));
y1(m_sMsgToNode, 0, sizeof(m_sMsgToNode));
y1(y9, 0, sizeof(y9));y1(y8, 0, sizeof(y8));}
TMsgTotalChkFieldReq::TMsgTotalChkFieldReq(){y1(j1, 0, sizeof(j1));
y1(m_sCardType, 0, sizeof(m_sCardType));y1(j2, 0, sizeof(j2));
y1(m_sBillNumber, 0, sizeof(m_sBillNumber));y1(y6, 0, sizeof(y6));}
TMsgTotalChkFieldRes::TMsgTotalChkFieldRes(){y1(j1, 0, sizeof(j1));
y1(m_sCardType, 0, sizeof(m_sCardType));y1(j2, 0, sizeof(j2));
y1(m_sBillNumber, 0, sizeof(m_sBillNumber));y1(y6, 0, sizeof(y6));y1(y7, 0, sizeof(y7));}
//Description: TMsg构造函数1,设置默认成员变量
TMsg::TMsg(): m_iMsgType(-1), m_iMsgLength(-1){}
TMsg::TMsg(int iMsgType): m_iMsgType(iMsgType), m_iMsgLength(-1){}
TMsg::~TMsg(){}
int TMsg::getMsgType(){return m_iMsgType;}
int TMsg::getMsgLength(){return m_iMsgLength;} --------------------编程问答-------------------- // Description: TMsg成员函数,设置消息长度
void TMsg::setMsgLength(int iMsgLength){m_iMsgLength = iMsgLength;}
//Description: TMsg成员函数,将消息头进行解码
int TMsg::decodeMsg(char* sMsgInBuf, int iMsgInBufLength)
{z7;if (iMsgInBufLength < MsgHeadFieldLength){
ERRORLOG("TMsg::decodeMsg(),error msg length[" << iMsgInBufLength << "]. ");return 0;}
//必须消息的长度大于消息头的长度,才能解码
if (iMsgInBufLength > MsgHeadFieldLength){//解码消息头内容
y2(j8.y4, f1, MsgLengthFieldLength);
iMsgOffset += MsgLengthFieldLength;y2(j8.y5, f1, MsgCryptFieldLength);iMsgOffset += MsgCryptFieldLength;
y2(j8.m_sMsgStreamNo, f1, j5);iMsgOffset += j5;y2(j8.m_sMsgType, f1, MsgTypeFieldLength); f4;
y2(j8.j4, f1, NodeNoFieldLength);f5;y2(j8.m_sMsgToNode, f1, NodeNoFieldLength);f5;
y2(j8.y9, f1, j9);iMsgOffset += j9;y2(j8.y8, f1, FeeTypeFieldLength);f6;}z5;}
//Description: TMsg成员函数,将消息头进行编码
int TMsg::encodeMsg(char* sMsgOutBuf){if (NULL == sMsgOutBuf){
ERRORLOG("TMsg::encodeMsg(): output buffer pointer is invalid."); return 0;}z7;//编码消息头
y2(f2, j8.y4, MsgLengthFieldLength);
iMsgOffset += MsgLengthFieldLength;y2(f2, j8.y5, MsgCryptFieldLength);iMsgOffset += MsgCryptFieldLength;
y2(f2, j8.m_sMsgStreamNo, j5);iMsgOffset += j5;y2(f2, j8.m_sMsgType, MsgTypeFieldLength);
f4;y2(f2, j8.j4, NodeNoFieldLength);f5;y2(f2, j8.m_sMsgToNode, NodeNoFieldLength);
f5; y2(f2, j8.y9, j9);iMsgOffset += j9;y2(f2, j8.y8, FeeTypeFieldLength);f6;z5;}
//TMsg功能函数,主要打印成员函数信息到日志文件
void TMsg::dump(HOfstream& j6){j6.reopen();j6 << "MsgLength :" << j8.y4 << endl;
j6 << "MsgCryptIndex :" << j8.y5 << endl;j6 << "MsgStreamNo :" << j8.m_sMsgStreamNo << endl;
j6 << "MsgType :" << j8.m_sMsgType << endl;j6 << "MsgFromNode :" << j8.j4 << endl;
j6 << "MsgToNode :" << j8.m_sMsgToNode << endl;j6 << "MsgDateTime :" << j8.y9 << endl;
j6 << "MsgFeeType :" << j8.y8 << endl;j6.close();}
// Description: TMsgTotalChkReq构造函数,主要将数据成员清0
TMsgTotalChkReq::TMsgTotalChkReq(): m_iChkFieldCount(0)
{ m_iChkFieldCount = 0;y1(j1, 0, sizeof(j1));
y1(m_sStopStreamNo, 0, sizeof(m_sStopStreamNo));y1(m_sStartStreamNo, 0, sizeof(m_sStartStreamNo));
y1(m_sStopDateTime, 0, sizeof(m_sStopDateTime));y1(m_sStartDateTime, 0, sizeof(m_sStartDateTime));}
TMsgTotalChkReq::~TMsgTotalChkReq(){}
//Description: TMsgTotalChkReq功能函数,设置对帐字段个数
void TMsgTotalChkReq::setChkFieldCount(int iCount){m_iChkFieldCount = iCount;}
//TMsgTotalChkReq功能函数,返回对帐字段个数
int TMsgTotalChkReq::getChkFieldCount(){return m_iChkFieldCount;}
补充:Java , Web 开发