动态生成jsp 请各位高手帮忙 在线等!!!!

liqi_wj 2010-07-28 03:08:08
现在根据客户需求,不同的产品要对应不同的jsp(既页面上的输入框和下拉菜单不确定),这该怎么做啊?
刚才在网上搜索了下 找了个解决方法 就是:
<%
// 动态生成jsp文件,然后动态调用
String filename = "testDynamicInclude.jsp";
String path = application.getRealPath(".");
FileWriter fw = new FileWriter(path + "/" + filename);
fw.write("<" + "%@ page language=\"java\" contentType=\"text/html; charset=GBK\" pageEncoding=\"GBK\"%" + ">");
fw.write("<" + "%=new java.util.Date()%" + ">");
fw.close();
%>
<jsp:include page="<%=filename%>" />

但是个人感觉 因为我们的页面比较复杂 这样一个一个组件往里面写的话 好像挺费劲 不知道各位大虾们有什么高招啊 请多多指点 指点的好的话 我会追加分的
...全文
158 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
gufenglieying 2010-07-28
  • 打赏
  • 举报
回复
这是我编写的 一个js文件的 一部分 希望对楼主 有用
gufenglieying 2010-07-28
  • 打赏
  • 举报
回复
动态生成input框的js脚本 很好用 带删除 清空列表功能
gufenglieying 2010-07-28
  • 打赏
  • 举报
回复
function findObj(theObj, theDoc)
{
var p, i, foundObj;
if (!theDoc) theDoc = document;
if ((p = theObj.indexOf("?")) > 0 && parent.frames.length)
{
theDoc = parent.frames[theObj.substring(p + 1)].document;
theObj = theObj.substring(0, p);
}
if (!(foundObj = theDoc[theObj]) && theDoc.all)
foundObj = theDoc.all[theObj];

for (i = 0; !foundObj && i < theDoc.forms.length; i++)
foundObj = theDoc.forms[i][theObj];

for (i = 0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
foundObj = findObj(theObj, theDoc.layers[i].document);

if (!foundObj && document.getElementById)
foundObj = document.getElementById(theObj);

return foundObj;
}
//添加一个参与人填写行
function AddSignRow() { //读取最后一行的行号,存放在txtTRLastIndex文本框中
var txtTRLastIndex = findObj("txtTRLastIndex", document);
/* alert(txtTRLastIndex.value);*/
var rowID = parseInt(txtTRLastIndex.value);

var signFrame = findObj("SignFrame", document);
//添加行
var newTR = signFrame.insertRow(signFrame.rows.length);
newTR.id = "SignItem" + rowID;

//添加列:序号
var newNameTD = newTR.insertCell(0);
//添加列内容
newNameTD.innerHTML = newTR.rowIndex.toString();

//添加列:checkbox
var newCompanyTD = newTR.insertCell(1);
//添加列内容
newCompanyTD.innerHTML = "<input name='checkbox' id='checkbox" + rowID + "' type='checkbox' value=" + rowID + " size='20' />";


//添加列:username
var newNameTD = newTR.insertCell(2);
//添加列内容
newNameTD.innerHTML = "<input name='username" + rowID + "'id='username" + rowID + "' type='text' size='12' />";
/*newNameTD.innerHTML = "<input name='role" + rowID + "'id='role" + rowID + "' type='checkbox' size='12' />";*/

//添加列:usersex
var newEmailTD = newTR.insertCell(3);
//添加列内容
newEmailTD.innerHTML = "<input name='usersex" + rowID + "' id='usersex" + rowID + "' type='text' size='20' />";

//添加列:userage
var newTelTD = newTR.insertCell(4);
//添加列内容
newTelTD.innerHTML = "<input name='userage" + rowID + "' id='userage" + rowID + "' type='text' size='10' />";

//添加列:usercomment
var newMobileTD = newTR.insertCell(5);
//添加列内容
newMobileTD.innerHTML = "<input name='usercomment" + rowID + " ' id='usercomment" + rowID + "' type='text' size='12' />";


//添加列:删除按钮
var newDeleteTD = newTR.insertCell(6);
//添加列内容
newDeleteTD.innerHTML = "<div align='center' style='width:40px'><a href='javascript:;' onclick=\"DeleteSignRow('SignItem" + rowID + "')\">删除</a></div>";

//将行号推进下一行
// 返回 并保存数据
txtTRLastIndex.value = (rowID + 1).toString();
return rowID;
}
//删除指定行
function DeleteSignRow(rowid) {
var signFrame = findObj("SignFrame", document);
var signItem = findObj(rowid, document);

//获取将要删除的行的Index
var rowIndex = signItem.rowIndex;

//删除指定Index的行
signFrame.deleteRow(rowIndex);

//重新排列序号,如果没有序号,这一步省略
for (i = rowIndex; i < signFrame.rows.length; i++) {
signFrame.rows[i].cells[0].innerHTML = i.toString();
}
}//清空列表
function ClearAllSign() {
if (confirm('确定要清空所有吗?')) {
var signFrame = findObj("SignFrame", document);
var rowscount = signFrame.rows.length;

//循环删除行,从最后一行往前删除
for (i = rowscount - 1; i > 0; i--) {
signFrame.deleteRow(i);
}

//重置最后行号为1
var txtTRLastIndex = findObj("txtTRLastIndex", document);
txtTRLastIndex.value = "1";


}
}
wxx474341237 2010-07-28
  • 打赏
  • 举报
回复
可以使用标签如JSTL,毕竟你要根据从后台读出的数据去判断到底显示几个输入框
Canny 2010-07-28
  • 打赏
  • 举报
回复
给你顶上去,我发了帖子,你也给我顶上去。嘿嘿!
liqi_wj 2010-07-28
  • 打赏
  • 举报
回复
哎 都没听明白我说什么啊
myloveyoyo1314 2010-07-28
  • 打赏
  • 举报
回复
如果 只是几种情况 就把几种情况 写成几个jsp动态调用 或者在一个页面弄几个div 控制显示就完了呗
liqi_wj 2010-07-28
  • 打赏
  • 举报
回复
能不能告诉我怎么动态生成jsp啊 感觉用js不太适合我们的项目!
niu90 2010-07-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 liqi_wj 的回复:]

引用 5 楼 niu90 的回复:
引用 3 楼 liqi_wj 的回复:

根据需求 输入框的数量是不确定的 用js或el限定的只是固定数量的输入框!
js也可以在不确定情况下生成对应数量的输入框


那js可以在jsp页面上产生新的输入框吗?
[/Quote]可以,js与jsp、asp等语言无关,只和浏览器解析有关
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 liqi_wj 的回复:]
那js可以在jsp页面上产生新的输入框吗?
[/Quote]

当然可以了。
liqi_wj 2010-07-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 niu90 的回复:]
引用 3 楼 liqi_wj 的回复:

根据需求 输入框的数量是不确定的 用js或el限定的只是固定数量的输入框!
js也可以在不确定情况下生成对应数量的输入框
[/Quote]

那js可以在jsp页面上产生新的输入框吗?
liqi_wj 2010-07-28
  • 打赏
  • 举报
回复
因为产品会一直增加 增加的产品的属性又是不确定的 即A产品有姓名和性别两个属性 而B产品有姓名和年龄两个属性 而C产品现在没上线呢 也不知道他有什么属性
niu90 2010-07-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 liqi_wj 的回复:]

根据需求 输入框的数量是不确定的 用js或el限定的只是固定数量的输入框!
[/Quote]js也可以在不确定情况下生成对应数量的输入框
niu90 2010-07-28
  • 打赏
  • 举报
回复
动手先规划一下,是否存在重复的内容,css的使用,js的复用,等等,页面上的输入框不确定是什么不确定呢??位置?样式?不同的产品要对应不同的jsp?怎么不做不同的页面呢??一定要动态生成?
liqi_wj 2010-07-28
  • 打赏
  • 举报
回复
根据需求 输入框的数量是不确定的 用js或el限定的只是固定数量的输入框!
xieruilin 2010-07-28
  • 打赏
  • 举报
回复
一个页面,用el或js根据不同条件显示不同内容,为何要动态生成JSP?没这样做法的吧?
liqi_wj 2010-07-28
  • 打赏
  • 举报
回复
怎么没有人来啊 ?难道帖子要沉啊!!!!!!!

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧