使用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) {
}
%>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值