如何从 java 脚本重定向到 struts 动作?
how to redirect to struts action from java script?
如果脚本中的条件成功,那么我需要在配置 xml 中调用一个操作,否则调用控件的任何操作都不需要停留在同一页面上?请帮忙?
if condition in the script got success then i need to invoke one action in the config xml, otherwise no action invoking the control needs to stay at same page? please help on this?
Java 脚本
function displayDate()
{
var x=document.getElementsByName("userName")
if(x = "shan")
{
alert("shankarasd");
document.myForm.action ="/setUpForInsertOrUpdate";
document.myForm.submit();
}
}
HTML
<html>
<body>
<s:form action="HelloWorld" >
<s:textfield name="userName" label="User Name" />
<s:submit onclick="displayDate()" />
</s:form>
</body>
</html>
config.xml
<struts>
<package name="default" extends="struts-default">
<action name="HelloWorld" class="vaannila.HelloWorld.HelloWorld">
<result name="SUCCESS">/success.jsp</result>
</action>
<action name="setUpForInsertOrUpdate" method="setUpForInsertOrUpdate" class="vaannila.HelloWorld.HelloWorld">
<result name="SUCCESS1">/success1.jsp</result>
</action>
<action name="back" method="back" class="vaannila.HelloWorld.HelloWorld">
<result name="SUCCESS2">/success.jsp</result>
</action>
</package>
</struts>
试试看
window.location='youractionname'
这会将您的窗口重定向到您的目的地
This will redirect your window into your destination
如果您想将您的值发送到其他页面,请按照此方法
If you want to sent your values to other page, then follow this method
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function displayDate()
{
var x=document.getElementsByName("userName")
if(x =="shan")
{
alert("Redirecting");
return true;
}
else{
alert("Not Redirecting");
return false;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<s:form action="HelloWorld" onsubmit="displayDate();">
<s:textfield name="userName" label="User Name" />
<s:submit onclick="displayDate()" />
</s:form>
</body>
</html>
我修改的是,将函数调用从按钮更改为表单提交.并从函数中删除不需要的东西
What I modified is, changed the function calling from button to form submit. And removed the unwanted things from function
这篇关于如何从struts 2 中的java 脚本重定向到struts 动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
即使在调用 abort (jQuery) 之后,浏览器也会等待Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在调用 abort (jQuery) 之后,浏览器也会等待 ajax 调用
JavaScript innerHTML 不适用于 IE?JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不适用于 IE?)
XMLHttpRequest 无法加载,请求的资源上不存在“AXMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 无法加载,请求的资
XHR HEAD 请求是否有可能不遵循重定向 (301 302)Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 请求是否有可能不遵循重定向 (301 302))
NETWORK_ERROR:XMLHttpRequest 异常 101NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 异常 101)
XMLHttpRequest 206 部分内容XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分内容)