`
baron.unsafe
  • 浏览: 79385 次
社区版块
存档分类
最新评论

使用javascript调用jsp代码

阅读更多

<%@page pageEncoding="GBK"%>
<%@page import="java.io.*"%>
<%@page import="java.util.*"%>
<%!
//FileName
private static  String PWD="";
public static Map<String,Call> map=new HashMap<String,Call>();
%>
<%
//get Filename
PWD=request.getServletPath().substring(request.getServletPath().lastIndexOf("/")+1);
%>
<%!
	//Innerface
	private static interface Call{
		public void cal(HttpServletRequest request,HttpServletResponse response)throws Exception;
		public boolean doBefore();
	}
	//ImplClass
	private static class callimpl implements Call{
		public void cal(HttpServletRequest request,HttpServletResponse response)throws Exception {
		}
		public boolean doBefore(){return true;}
	}
	
	//javascript
	public static class script extends 	callimpl{
		public void cal(HttpServletRequest request,HttpServletResponse response)throws Exception{
			try{
				PrintWriter out=response.getWriter();
			out.println(
			"<html><head><title>I am Baron</title>"+
			"</head>"+"<body>");
			out.println(
			"<script type=\"text/javascript\">"+
			"function fso(obj) {"+
			"};"+
			"function doPost(obj) {"+
			"var form = document.forms[\"doForm\"];"+
			"var elements = form.elements;for (var i = form.length - 1;i>=0;i--){form.removeChild(elements[i])}"+
			"for (var pro in obj)"+
			"{"+
			"var input = document.createElement(\"input\");"+
			"input.type = \"hidden\";"+
			"input.name = pro;"+
			"input.value = obj[pro];"+
			"form.appendChild(input);"+
			"}"+
			"form.submit();"+
			"}"+
			"</script>");
			}catch(Exception e){e.printStackTrace();}
		}
	}
	
	//First
	private static class first extends callimpl{
		public void cal(HttpServletRequest request,HttpServletResponse response) throws Exception{
			PrintWriter out=response.getWriter();
			out.println("First");
		}
	}
	
	//second
	private static class second extends callimpl{
		public void cal(HttpServletRequest request,HttpServletResponse response) throws Exception{
			PrintWriter out=response.getWriter();
			out.println("Second");
		}
	}
	
	//Third
	private static class Third extends callimpl{
		public void cal(HttpServletRequest request,HttpServletResponse response) throws Exception{
			PrintWriter out=response.getWriter();
			out.println("Third");
		}
	}
	
	//Fourth
	private static class Fourth extends callimpl{
		public void cal(HttpServletRequest request,HttpServletResponse response) throws Exception{
			PrintWriter out=response.getWriter();
			out.println("Fourth");
		}
	}
	
	//top
	private static class top extends callimpl{
		public void cal(HttpServletRequest request,HttpServletResponse response)throws Exception{
			PrintWriter out=response.getWriter();
			out.println("<form action=\""+PWD+"\" method=\"post\" name=\"doForm\"></form>"+
			"<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"+
			"<tr >"+
			"<a href=\"javascript:doPost({b:'first'});\">First</a> | "+
			"<a href=\"javascript:doPost({b:'second'});\">Second</a> | "+
			"<a href=\"javascript:doPost({b:'Third'});\">Third</a> | "+
			"<a href=\"javascript:doPost({b:'Fourth'});\">Fourth</a>"+
			"</tr>"+
			"</table></body></html>"
			);
		}
	}
	//static code
	static {
		map.put("top",new top());
		map.put("script",new script());
		map.put("first",new first());
		map.put("second",new second());
		map.put("Third",new Third());
		map.put("Fourth",new Fourth());	
	}
%>

<% 
try {
String o = request.getParameter("b");
Call in = map.get(o);
if (in == null) {
response.sendRedirect(PWD+"?b=second");
} else {
map.get("script").cal(request,response);
map.get("top").cal(request,response);
in.cal(request,response);
}
} catch (Exception e) {
}
%>


0
0
分享到:
评论

相关推荐

    ASP.NET中前台javascript与后台代码调用

    ASP.NET中前台javascript与后台代码调用

    Javascript调用WebService

    使用javascript 中Ajax技术调用WebService,包括JSP和ASP.NET中两种,其中JSP的WebService使用了XFire框架。 ASP.NET中的WebService做了一个方法示例GetProgress,包含3个参数。 JSP中的WebService做了hello方法的...

    Javascript调用C#函数示例程序

    一个在HTML中使用Javascript的window.external调用C#内函数的示例程序。该方法可应用于网页程序开发中的网页-程序沟通,例如用C#的IHTMLWindow2.execScript替换HTML默认Javascript方法使其直接与C#传参、通讯。

    JSP脚本元素调用Java代码.ppt

    JSP脚本元素调用Java代码.ppt

    JavaScript完全自学宝典 源代码

    1.本书1~21章所附代码的运行环境 操作系统:Windows 2003、Windows XP Professional,或者Windows 2000 开发环境:UltraEdit12.10a、eclipse-jee-europa Web浏览器:Microsoft Internet Explorer 6.0及以上版本 ...

    document.write()在JavaScript中怎样JSP调用

    document.write()在JavaScript中怎样JSP调用

    jsp页面调用applet实现人民币的大小写转换.docx

    本文主要讲述了如何使用JSP页面调用Applet实现人民币的大小写转换。该实现方法通过在JSP页面中嵌入一个Applet,使用JavaScript与Applet进行交互,实现实时的人民币大小写转换。 一、JSP页面调用Applet的实现 在JSP...

    JSP API接口和返回的版本

    目前所有版本的JS JSP ASP .NET J2AM 都是提供源代码的,对于一些脚本语言来说,直接解压缩之后就可以使用了,不需要什么安装步骤。另外一些需要编译的语言,则提供了编译用的 shell 文件(Linux/Unix 下使用)和 ...

    用javascript和JSP写的画面输入画面

    这是我用javascript和JSP写的画面输入画面,如何通过纯&quot;Java&quot;写这个输入画面,并被JSP调用? 论坛中不能上传图片,我只好放在这里了!不好意思啦!

    JSP动态网页制作基础培训教程源代码.rar

    第10章源代码使用说明 操作步骤如下: 1.建立后台SQL Server数据库。读者应该确保计算机上安装有SQL Server 2000服务器,启动SQL Server服务后,打开查询分析器,然后执行本章目录下的db.sql文件自动生成并初始化...

    jsp+JavaScript+struts+hibernate+css+mysql的网上书店

    利用jsp、struts、hibernate开发JavaWeb应用

    JSP网页播放器 (调用WMP)

    用jsp写的一个网页播放器,用到servlet,javabean,jsp,javascript,数据库为mysql

    javascript 常用代码大全

    一、验证类 1、数字验证内 1.1 整数 1.2 大于0的整数 (用于传来的id的验证) 1.3 负整数的验证 1.4 整数不能大于imax 1.5 整数不能小于imin ...16, 刷新/模拟无刷新 异步调用类(xmlhttp或iframe,frame)

    JSP网络编程从基础到实践的实例代码

    第7章 在JSP中使用数据库 实例43 顺序查询数据库表中的数据 实例44 移动查询 实例45 参数查询 实例46 模糊查询 实例47 综合查询 实例48 追加记录 实例49 删除记录 实例50 更新记录 实例51 分页显示记录 ...

    JSP(全称JavaServer Pages)

    JSP引入了被称为“JSP动作”的XML标签,用来调用内建功能。另外,可以创建JSP标签库,然后像使用标准HTML或XML标签一样使用它们。标签库能增强功能和服务器性能,而且不受跨平台问题的限制。JSP文件在运行时会被其...

    在JS中如何调用JSP中的变量

    在JS中调用JSP中的变量: 代码如下: &lt;&#37; int coblid=Integer.parseInt(request.getParameter(“blid”)); %&gt; [removed] var coblid='&lt;&#37;=coblid%&gt;’ ; [removed]

    jsp调用uploadify文件上传插件实现文件快速上传.rar

    jsp使用uploadify插件实现文件上传的示例,测试时将uploadify 直接导入myeclipse就能用了。  uploadify是一个与jquery和flash结合实现的上传程序,界面挺漂亮,用起来也方便,不过浏览器需要安装有Flash插件,好像...

    jsp虚拟键盘操作

    jsp虚拟键盘操作 javascript代码虚拟键盘

    jsp页面中插入css样式的三种方法总结.docx

    jsp页面中插入css样式的三种方法是开发中常见的需求,本文将对三种方法进行总结介绍,并对每种方法的使用场景和优缺点进行分析。 外部样式 外部样式表是将css代码写入到一个独立的文件中,并通过link标签将其链接到...

    Ajax发送请求js代码

    打包好的Ajax代码,实现了对象化,使用时直接调用就可以了,调用时需要重构三个方法,如下: &lt;script type="text/javascript"&gt; function onerror() //错误处理方法 { alert("error"); } function getInfo() //...

Global site tag (gtag.js) - Google Analytics