讨论:JSP系统结构的应用模式

bukebushuo 2003-09-29 02:40:10
大家好,我最近试用了一个WEB系统,多层结构,客户端为HTML,使用JRUN+IIS
工作原理是HTML页面SUBMIT后,SERVLET取得叶面URL,然后取得所有参数,提交得到返回的数据,然后根据取得的URL读取HTML,然后把传回来的数据一起重新构造一个叶面送回客户端。大体就是这样的。
我想问的是,有没有人以前用过这样的系统或者技术?就是读取叶面代码,结合已有数据重新生成包含数据的叶面,然后送回!
...全文
28 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
gks_cn 2003-09-29
  • 打赏
  • 举报
回复
驱动的bean
// $Id: Dept.java,v 1.6 2000/01/10 19:08:14 gongke Exp $
package peiyang.priv;

import util.db.DB;
import sun.jdbc.rowset.CachedRowSet;
import util.string.StringUtil;
import java.util.Vector;
import java.sql.*;
import java.io.*;

public class Dept{
private int deptId;
private String deptName;
private String deptDiscription;
private String note;
private String action = ""; //控制器
private boolean valid = true;
private String erroMsg = "";
private String statusMsg;
public String getAction() {
return this.action;
}

public void setAction(String action) {
this.action = action;
}

public int getDeptId() {
return this.deptId;
}

public void setDeptId(int deptId) {
this.deptId = deptId;
}

public void setDeptName(String deptName) {
this.deptName = deptName;
}

public String getDeptName() {
return this.deptName;
}

public void setDeptDiscription(String deptDiscription) {
this.deptDiscription = deptDiscription;
}

public String getDeptDiscription() {
return this.deptDiscription;
}

public void setNote(String note) {
this.note = note;
}

public String getNote() {
return this.note;
}

public Dept() {
}

public void escapSQLTag() {
this.deptDiscription = util.string.StringUtil.escapeSQLTags(this.
deptDiscription);
this.deptName = util.string.StringUtil.escapeSQLTags(this.
deptName);
this.note = util.string.StringUtil.escapeSQLTags(this.
note);
}

public String dbProcess() {
DB mydb = new DB();
String msg = null;
if (this.action.equals("add")) { //收到添加的信息就添加
try {
escapSQLTag();
if (this.isValid()) {
String sql =
"insert into Dept (deptId,deptName,deptDiscription,note)" +
"values (s_deptId.nextval,'" + StringUtil.toGb(this.deptName) +
"','" +
StringUtil.toGb(this.deptDiscription) + "','" +
StringUtil.toGb(this.note) + "')";
System.out.println(sql);
mydb.execute(sql);
msg = "<script> alert('添加成功')</script>";
}
else {
msg = "<script> alert ('" + this.getErroMsg() + "')</script>";
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
if (this.action.equals("del")) { //收到删除的信息就添加
try {
String sql = "delete from Dept where deptId=" + this.deptId;
System.out.println(sql);
mydb.execute(sql);
msg = "<script>alert('删除成功')</script>";

}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
if (this.action.equals("edit")) { //收到修改的信息就添加
try {
escapSQLTag();
if (this.isValid()) {
String sql = "update Dept set deptName='" +
StringUtil.toGb(this.deptName)
+ "',deptDiscription='" + StringUtil.toGb(this.deptDiscription)
+ "',note='" + StringUtil.toGb(this.note)
+ "' where deptId=" + this.deptId;
System.out.println(sql);
mydb.execute(sql);
msg = "<script>alert('修改成功')</script>";
}
else {
msg = "<script> alert ('" + this.getErroMsg() + "')</script>";
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
return msg;
}

public void loadRecord() {
DB mydb = new DB();
try {
String sql = "select * from Dept where deptId=" + this.deptId;
System.out.println(sql);
CachedRowSet rs = mydb.executeQuery(sql);
if (rs.next()) { //返回数据库记录
this.deptDiscription = rs.getString("deptDiscription");
this.deptName = rs.getString("deptName");
this.note = rs.getString("note");
}
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}

public CachedRowSet getList() throws SQLException {
CachedRowSet rs = new CachedRowSet();
DB mydb = new DB();
String sql = "select * from Dept";
rs = mydb.executeQuery(sql);
return rs;
}

private boolean isStringValid(String s, int maxlength) {
if (s != null) {
if (s.length() > maxlength) {
return false;
}
}
else {
return false;
}
return true;
}

public boolean isValid() {
if (!isStringValid(this.deptName, 50)) {
this.setErroMsg("部门不能为空,并且长度不能大于50");
this.setValid(false);
return false;
}
this.setValid(true);
return true;
}

public void setValid(boolean valid) {
this.valid = valid;
}

public String getErroMsg() {
return erroMsg;
}

public void setErroMsg(String erroMsg) {
this.erroMsg = erroMsg;
}

public static void main(String args[]) {
Dept d = new Dept();
d.setAction("add");
d.setDeptName("a");
d.setNote("n");
System.out.println(d.isValid());
System.out.println(d.getErroMsg());
}
public String getStatusMsg() {
return statusMsg;
}
public void setStatusMsg(String statusMsg) {
this.statusMsg = statusMsg;
}
}
gks_cn 2003-09-29
  • 打赏
  • 举报
回复
<%// $Id: edit.jsp,v 1.10 2000/01/10 18:43:18 gongke Exp $%>
<%@ page contentType="text/html; charset=gb2312" %>
<%@ include file="../../inc/head.jsp"%>
<jsp:useBean id="dept" class="peiyang.priv.Dept" scope="request">
<jsp:setProperty name="dept" property="*"/>
</jsp:useBean>
<%
dept.loadRecord();//将数据库里面的记录通过deptid传到bean里面
%>
<html>
<head>
<title>
</title>
<link rel="stylesheet" href="../../inc/main.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body background="../../images/line.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
<br>
<form name="form1" method="post" action="process.jsp">
<table width="600" border="0" cellpadding="0" cellspacing="0" >
<tr height=25>
<td class=cl1_titleoff align=center colspan=2><font class=m2_1>部门</font></td>
</tr>
<tr>
<td class="mode4"> <img src=../../images/blank.gif width=10 height="1">部门名称</td>
<td class="mode5"><img src="../../images/blank.gif" width="10" height="1">
<input name="deptName" type="text" class="huaxian" id="deptName" value="<jsp:getProperty
name="dept" property="deptName"/>"> </td>
</tr>
<tr>
<td class="mode4"><img src=../../images/blank.gif width=10 height="1">部门描述</td>
<td class="mode5"><img src="../../images/blank.gif" width="10" height="1">
<textarea name="deptDiscription" cols="50" rows="5" class="huaxian" id="deptDiscription"><jsp:getProperty
name="dept" property="deptDiscription"/></textarea>
</td>
</tr>
<tr>
<td class="mode4"><img src=../../images/blank.gif width=10 height="8">备注</td>
<td class="mode5"><img src="../../images/blank.gif" width="10" height="1">
<input name="note" type="text" class="huaxian" id="note" value="<jsp:getProperty
name="dept" property="note"/>"> </td>
</tr>
<tr>
<td class="mode4"><img src=../../images/blank.gif width=10 height="8">相关操作
</td>
<td class="mode5"><img src="../../images/blank.gif" width="10" height="1">
<%
if (request.getParameter("action")==null){
%> <input name="edit" type="submit" class="cl2_ipt" value="添加" onClick="form1.action.value='add'">
<%
}else{
%> <input name="edit" type="submit" class="cl2_ipt" value="编辑" onClick="form1.action.value='edit'">
<input name="deptId" type="hidden" id="deptId" value="<jsp:getProperty name="dept" property="deptId"/>">
<input name="del" type="submit" class="cl2_ipt" value="删除" onClick="form1.action.value='del'">
<%
}
%>
<input name="action" type="hidden" id="action"> <input name="button" type="button" class="cl2_ipt" value="返回" onClick="window.location='index.jsp'">
</td>
</tr>
</table>
<br>
<jsp:getProperty name="dept" property="erroMsg"/>
</form>
</center>
</body>
</html>

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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