【问题】
如何不点击提交按钮,就能显示Server端的信息?【环境】
eclipse7.5 JRE7 J2EE1.4 tomcat7【struts.xml】
<action name="HelloWorld2" class="helloWorld.HelloWorld2">
<result name="SUCCESS">/HelloWorld2.jsp</result>
</action>【action】
public class HelloWorld2{
private String message; public String getMessage() {
return message;
}
public String execute() throws Exception{
message = "HelloWorld2 from server";
return "SUCCESS";
}
}【jsp】
<%@ page contentType="text/html;charset=GBK" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<title>Hello World2</title>
</head>
<body>
<s:form action="HelloWorld2" >
<h1><s:property value="message"/></h1>
<!-- <s:submit/>
--> </s:form>
</body>
</html>
如何不点击提交按钮,就能显示Server端的信息?【环境】
eclipse7.5 JRE7 J2EE1.4 tomcat7【struts.xml】
<action name="HelloWorld2" class="helloWorld.HelloWorld2">
<result name="SUCCESS">/HelloWorld2.jsp</result>
</action>【action】
public class HelloWorld2{
private String message; public String getMessage() {
return message;
}
public String execute() throws Exception{
message = "HelloWorld2 from server";
return "SUCCESS";
}
}【jsp】
<%@ page contentType="text/html;charset=GBK" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
<title>Hello World2</title>
</head>
<body>
<s:form action="HelloWorld2" >
<h1><s:property value="message"/></h1>
<!-- <s:submit/>
--> </s:form>
</body>
</html>
解决方案 »
- 使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10
- BufferedReader的readline()方法
- struts2 默认Action问题,,急啊!
- 请教一个问题${参数} 操作问题
- 如何解决多类继承的问题?
- java调用c#写的webservice,参数丢失问题
- 采用tc4ntiis整合tomcat和iis后,uriworkermap.properties如何配置多域名?
- getHibernateTemplate().find()空指针问题
- 怎么限制一个方法中传入的某个参数只能是int或者是String类型,我考虑的是枚举但是不知道这个枚举怎么写
- 极品难题,java中的中文乱码问题,问题的症结已经知道
- log4j的bug,有谁能解决下
- java连接oracle数据库警告,在线等大神。
如果不点提交,就没有请求,
除非用服务器推送技术,服务器自动发送数据给客户端。
ajax的特点是局部刷新,这这个页面很明显需要的是全刷新,所以ajax是不适用的。
下面提供一种不使用submit按钮的方式。
<script type="text/javascript">
function checkForm(f){
//提交之前可以使用一些验证
f.submit();
}
</script>
<body>
<form name="myForm" action="UserRegisterServlet" method="post">
用户名:<input type="text" name="name" id="name" onblur="checkName(this.value)" /><span id="spanName"></span><br>
<img alt="" style="cursor: pointer" src="image/register.gif" onclick="checkForm(this.parentNode)">
</form>
</body>
上面显示的按钮其实是一张图片。