Strut2中實現button頁面跳轉
阿新 • • 發佈:2019-01-03
在xx.jsp中存在某一button,程式碼如下:
<input type="button" value="登 錄" class="denglu" onclick="login()"/>則首先在xx.jsp中寫js:
<script type="text/javascript" >//登入
function login()
{
form1.action = "<%= _basePath%>/login";
form1.submit();//當前頁面提交
之後開啟struts.xml,在其中新增程式碼:
<action name="login" >//其中login為“form1.action = "<%= _basePath%>/login";”中的login。
<result>/main1.jsp</result>
</action>
跳轉到main1.jsp
<input type="button" value="登 錄" class="denglu" onclick="login()"/>則首先在xx.jsp中寫js:
<script type="text/javascript" >//登入
function login()
{
form1.action = "<%= _basePath%>/login";
form1.submit();//當前頁面提交
}
</script>
其中form1為你定義的button所在的表單(form)的id。
_basePath是地址。
String _path = request.getContextPath();//獲取專案路徑
String _basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+_path;
之後開啟struts.xml,在其中新增程式碼:
<action name="login" >//其中login為“form1.action = "<%= _basePath%>/login";”中的login。
<result>/main1.jsp</result>
</action>
跳轉到main1.jsp