送分的问题,很简单哦,100分。

ftisray 2004-09-22 09:12:33
数据库是oracle。
我需要做一个录入功能的addnew.jsp页面,需要实现以下4个功能:保存返回,保存继续,重置,返回(返回到union.jsp)。
<font face="Webdings" class="redcolor">4</font><a href="javascript:myInsert(document.formPost)"><%=res.getString("SAVE_BACK")%></a>  
<font face="Webdings" class="redcolor">4</font><a href="javascript:myInsMore(document.formPost)"><%=res.getString("SAVE_CONTINUE")%></a>  
<font face="Webdings" class="redcolor">4</font><a href="javascript:document.formPost.reset()"><%=res.getString("RESET")%></a>  
<font face="Webdings" class="redcolor">4</font><a href="javascript:myQuery(document.formPost)"><%=res.getString("BACK")%></a>
谁能帮忙具体写一下myInsert(),myInsMore(),myQuery()。
保存这些数据的表是:union_tab。 addnew.jsp中有id,name 2项。需要连接数据库时用javabean就行。
...全文
152 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
gumplei 2004-09-23
<script language="javascript">
String sql;
dBBean.connect();
ResultSet rs=null;
function myAddNew(formHidden)
{
String sql;
dBBean.connect();
ResultSet rs=null;
String corp_name = request.getParameter("corp_name");
String corp_style = request.getParameter("corp_style");
String corp_city =request.getParameter("corp_city");
String corp_addr = request.getParameter("corp_addr");
String corp_phone = request.getParameter("corp_phone");
String memb_treat =request.getParameter("memb_treat");
String corp_intro =request.getParameter("corp_intro");

sql = "INSERT INTO insert_tab VALUES('+"corp_name"+',corp_syle,cor_city,corp_addr,corp_phone,memb_treat,corp_intro)";

int flag = dBBean.executeUpdate(sql);
if (flag==1) out.print("success");
else out.print("failed!");

window.location.href='union.jsp';
dBBean.close();
}

function myQuery(formHidden)
{
formHidden.opFlag.value="query";
formHidden.target = "_self";
formHidden.submit();
}

function myModify(formHidden,s_code,m_code)
{
formHidden.sys_code.value = s_code ;
formHidden.year.value = m_code ;
formHidden.opFlag.value="modify";
formHidden.target = "_self";
formHidden.submit();
}

function myDelete(formHidden,s_code,m_code)
{
if (!confirm("<%=res.getString("WANT_DEL")%>")) return ;
formHidden.opFlag.value="delete";
formHidden.sys_code.value = s_code ;
formHidden.year.value = m_code ;
formHidden.target = "_self";
formHidden.submit();
}

function myInsert(formPost)
{

if (!checkInsert(formPost)) return ;

formPost.opFlag.value="insert";
formPost.target = "_self";
formPost.submit();
}

function myInsMore(formPost)
{
if (!checkForm(formPost)) return ;

formPost.opFlag.value="insMore";
formPost.target = "aux";
formPost.submit();
formPost.reset();
}

/*function checkInsert(formPost)
{
if (!checkObjLen(formPost.sys_code,1,5,"<%=res.getString("SYS_CODE")%>")) return false ;
if (!checkYear(formPost.year)) return false ;
if (!checkForm(formPost)) return false ;

return true;
}

function checkForm(formPost)
{

if (formPost.db_pass.value!=formPost.db_pass1.value)
{
alert("<%=res.getString("DB")+res.getString("PASSWORD")+res.getString("MUST_EQUAL")+res.getString("CONFIRM_PASSWORD")%>");
formPost.db_pass.focus();
return false;
}

if (!checkObjLen(formPost.db_code,1,16,"<%=res.getString("DB")+res.getString("CODE")%>")) return false ;
if (!checkObjLen(formPost.db_name,1,20,"<%=res.getString("DB")+res.getString("NAME")%>")) return false ;
if (!checkObjLen(formPost.db_url,1,200,"<%=res.getString("DB")%>URL")) return false ;
if (!checkObjLen(formPost.db_user,1,40,"<%=res.getString("OS")+res.getString("USER")%>")) return false ;
if (!checkObjLen(formPost.db_pass,1,40,"<%=res.getString("OS")+res.getString("PASSWORD")%>")) return false ;

return true;
} */

function myUpdate(formPost)
{
if (!checkForm(formPost)) return ;

formPost.opFlag.value="update";
formPost.target = "_self";
formPost.submit();
}

function myUpdMore(formPost)
{
if (!checkForm(formPost)) return ;

formPost.opFlag.value="updMore";
formPost.target = "aux";
formPost.submit();
}

</script>
回复
gumplei 2004-09-23
我这里有一个类似的,你看看。
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<%@page import="java.lang.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@include file="union.js"%>
<jsp:useBean id="dBBean" scope="request" class="dbbean.movdb">
</jsp:useBean>

<form name="form1" method="post" action="">
<table width="768" border="0">
<tr>
<th bgcolor="#FFFFFF" scope="col"> </th>
</tr>
<tr>
<td bgcolor="#FFFFFF"><table width="500" border="0" align="center">
<tr>
<th width="102" scope="col"><div align="right"> 单位名称 </div></th>
<th width="388" scope="col"><div align="left">
<input name="corp_name" type="text" id="corp_name">
</div></th>
</tr>
<tr>
<td><div align="right"> 类别 </div></td>
<td bordercolor="#D4D0C8"><div align="left">
<select name="corp_style" id="corp_style">
<option selected>健身</option>
<option>KTV</option>
<option>特色餐饮</option>
<option>购物</option>
<option>旅游</option>
<option>酒吧</option>
<option>书店</option>
<option>音像</option>
</select>
</div></td>
</tr>
<tr>
<td><div align="right">城市</div></td>
<td bordercolor="#D4D0C8"><input name="corp_city" type="text" id="corp_city"></td>
</tr>
<tr>
<td><div align="right"> 详细地址 </div></td>
<td><div align="left">
<input name="corp_addr" type="text" id="corp_addr">
</div></td>
</tr>
<tr>
<td><div align="right"> 联系电话 </div></td>
<td><div align="left">
<input name="corp_phone" type="text" id="corp_phone">
</div></td>
</tr>
<tr>
<td><div align="right"> 会员待遇 </div></td>
<td><div align="left">
<input name="memb_treat" type="text" id="memb_treat">
</div></td>
</tr>
<tr>
<td><div align="right"> 联盟单位介绍 </div></td>
<td><div align="left">
<textarea name="corp_ally" id="corp_ally"></textarea>
</div></td>
</tr>
</table></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><div align="center">
<input type="submit" name="Submit" value="提交">
</div></td>
</tr>
</table>
<div align="justify"></div>
</form>
<table width="534" border="0" cellspacing=0 cellspadding=0>
<tr>
<td>
<font face="Webdings" class="redcolor">4</font><a href="javascript:myInsert(document.formPost)"><%=res.getString("SAVE_BACK")%></a>  
<font face="Webdings" class="redcolor">4</font><a href="javascript:myInsMore(document.formPost)"><%=res.getString("SAVE_CONTINUE")%></a>  
<font face="Webdings" class="redcolor">4</font><a href="javascript:document.formPost.reset()"><%=res.getString("RESET")%></a>  
<font face="Webdings" class="redcolor">4</font><a href="javascript:myQuery(document.formPost)"><%=res.getString("BACK")%></a>
</td>
</tr>
</table>
回复
ftisray 2004-09-22
java中对应的插入是这样的
else if (opFlag.equals("insert") || opFlag.equals("insMore")) //插入
{
String sys_code= request.getParameter("sys_code");
String year = request.getParameter("year");
String os_code = request.getParameter("os_code");
String db_type_code = request.getParameter("db_type_code");
String db_code = request.getParameter("db_code");
String db_name = request.getParameter("db_name");
String driver_manager = request.getParameter("driver_manager");
String db_url = request.getParameter("db_url");
String db_user=request.getParameter("db_user");
String db_pass=request.getParameter("db_pass");

sys_code = Show.getString(sys_code);
year = Show.getString(year);
os_code = Show.getString(os_code);
db_type_code = Show.getString(db_type_code);
db_code = Show.getString(db_code);
db_name = Show.getString(db_name);
driver_manager = Show.getString(driver_manager);
db_url = Show.getString(db_url);
db_user = Show.getString(db_user);
db_pass = Show.getString(db_pass);
db_pass = cerp_crypt.get_encoded_pass(db_pass);

if (sys_code.length()<1 || year.length()<1 )
{
outFlag = "0" ;
}else
{
sql = "insert into scg_db_config(company_code,sys_code,"
+ "year,os_code,db_type_code,db_code,db_name,"
+ "driver_manager,db_url,db_user,db_pass) values('"
+ companyCode + "','" + sys_code + "','" + year + "','"
+ os_code + "','" + db_type_code + "','" + db_code
+ "','" + db_name + "','" + driver_manager + "','"
+ db_url + "','" + db_user + "','" + db_pass + "')";

if (!pageQuery.simpleUpdate(sql))
outFlag = "0" ;
}

if (opFlag.equals("insert"))
{
pageQuery.getData(strFields,strTables,strConditions,
pageSize);
pageCount = pageQuery.pageCount ;
currentPage =
(currentPage>pageCount ? pageCount : currentPage);
vct = pageQuery.dividePage(currentPage,pageSize);
}
}
else if (opFlag.equals("modify"))
{
String sys_code= request.getParameter("sys_code");
String year = request.getParameter("year");

sys_code = Show.getString(sys_code);
year = Show.getString(year);

if (sys_code.length()>0 && year.length()>0)
{
strFields = "sys_code,year,db_code,db_name,os_code,"
+ "db_type_code,driver_manager,db_url,db_user,db_pass";

strTables = "scg_db_config";

strConditions = "company_code='" + companyCode
+ "' and sys_code='" + sys_code
+ "' and year='" + year + "'";

pageQuery.getData(strFields,strTables,strConditions,1);
vct = pageQuery.dividePage(1);

}

Vector osVct = null;
Vector dbVct = null;
Vector drVct = null;

int vctSize = 100 ;
pageQuery.getData("os_code,os_name","scg_os_type"
,"1=1 order by os_code",vctSize);

osVct = pageQuery.dividePage(1);

pageQuery.getData("db_type_code,db_type_name","scg_db_type",
"1=1 order by db_type_code",vctSize);

dbVct = pageQuery.dividePage(1);

pageQuery.getData("driver_manager",
"scg_driver_manager",
"1=1 order by driver_manager",vctSize);

drVct = pageQuery.dividePage(1);

request.setAttribute("osVct",osVct);
request.setAttribute("dbVct",dbVct);
request.setAttribute("drVct",drVct);

}
可是我编写的用javabean,没有所谓的java啊,真不知道该怎么办了
回复
ftisray 2004-09-22
union.js

function myAddNew(formHidden)
{
formHidden.opFlag.value="addNew";
formHidden.target = "_self";
formHidden.submit();
}

function myQuery(formHidden)
{
formHidden.opFlag.value="query";
formHidden.target = "_self";
formHidden.submit();
}

function myModify(formHidden,s_code,m_code)
{
formHidden.sys_code.value = s_code ;
formHidden.year.value = m_code ;
formHidden.opFlag.value="modify";
formHidden.target = "_self";
formHidden.submit();
}

function myDelete(formHidden,s_code,m_code)
{
if (!confirm("<%=res.getString("WANT_DEL")%>")) return ;
formHidden.opFlag.value="delete";
formHidden.sys_code.value = s_code ;
formHidden.year.value = m_code ;
formHidden.target = "_self";
formHidden.submit();
}

function myInsert(formPost)
{

if (!checkInsert(formPost)) return ;

formPost.opFlag.value="insert";
formPost.target = "_self";
formPost.submit();
}

function myInsMore(formPost)
{
if (!checkForm(formPost)) return ;

formPost.opFlag.value="insMore";
formPost.target = "aux";
formPost.submit();
formPost.reset();
}

/*function checkInsert(formPost)
{
if (!checkObjLen(formPost.sys_code,1,5,"<%=res.getString("SYS_CODE")%>")) return false ;
if (!checkYear(formPost.year)) return false ;
if (!checkForm(formPost)) return false ;

return true;
}

function checkForm(formPost)
{

if (formPost.db_pass.value!=formPost.db_pass1.value)
{
alert("<%=res.getString("DB")+res.getString("PASSWORD")+res.getString("MUST_EQUAL")+res.getString("CONFIRM_PASSWORD")%>");
formPost.db_pass.focus();
return false;
}

if (!checkObjLen(formPost.db_code,1,16,"<%=res.getString("DB")+res.getString("CODE")%>")) return false ;
if (!checkObjLen(formPost.db_name,1,20,"<%=res.getString("DB")+res.getString("NAME")%>")) return false ;
if (!checkObjLen(formPost.db_url,1,200,"<%=res.getString("DB")%>URL")) return false ;
if (!checkObjLen(formPost.db_user,1,40,"<%=res.getString("OS")+res.getString("USER")%>")) return false ;
if (!checkObjLen(formPost.db_pass,1,40,"<%=res.getString("OS")+res.getString("PASSWORD")%>")) return false ;

return true;
} */

function myUpdate(formPost)
{
if (!checkForm(formPost)) return ;

formPost.opFlag.value="update";
formPost.target = "_self";
formPost.submit();
}

function myUpdMore(formPost)
{
if (!checkForm(formPost)) return ;

formPost.opFlag.value="updMore";
formPost.target = "aux";
formPost.submit();
}

</script>
这个是我找到的类似的例子,但是这个没有用到javabean,其中的updMore这些东西都需要在java中实现啊。。。
回复
liugaojun 2004-09-22
简单的用js实现就ok了,不要搞的那么复杂。
回复
ftisray 2004-09-22
我第一次做页面,有想法,但是不知道怎么实现。
比如保存返回:
sql="insert ……(省略)";
int flag = dBBean.executeUpdate(sql);
if (flag==1) 跳转到union.jsp(不知道该怎么写);
else out.print("failed!");
保存继续也是类似。但是具体写我不知道该怎么写。
回复
runi 2004-09-22
我感觉不要用javascript的history来控制页面的跳转比较好,特别是这种有数据提交的页面,还是用servlet来控制吧!
回复
zskun 2004-09-22
楼上正解
回复
happyct 2004-09-22
既然是“送分的问题,很简单”那你自己还不轻易搞定啊?
回复
herogao 2004-09-22
别的不知道,我觉得返回可以这么做吧?
onclick="javascrip:distory.go(-1)"
好象是这么写的
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-22 09:12
社区公告
暂无公告