【问题】
如何不点击提交按钮,就能显示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>
解决方案 »
- 一年有52周,多出一天,现在是要在系统中做周报,客户要求每周都要上交周报,逻辑怎么弄?求高手,求解
- 求高手指教:把一个txt格式的文件传输到另一台机子上
- BufferedInputStream和BufferedOutputStream使用问题,复制文件之后文件中就没了数据,大家帮忙解决下
- 引入出现错误 getHibernateTemplate()
- 我可以参加吗?
- 寻找"structs 从零开始"这篇文章
- weblogic下的jsp页面内含有如下一行代码,出错?请高手指点!!!
- 如果采用动态验证struts1.1写好了struts-comfig.xml和validation.xml文件
- 在线等待...新做的struts例子在jboss下运行出错,而在tomcat下运行正常???
- 两个关系EJB问题
- 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>
上面显示的按钮其实是一张图片。