首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

struts2 点登陆按钮没有反应 (请高人帮忙看看什么原因),该怎么处理

2012-01-29 
struts2点登陆按钮没有反应 (请高人帮忙看看什么原因)divLogin.jsp代码如下:%@ page contentTypetext/h

struts2 点登陆按钮没有反应 (请高人帮忙看看什么原因)
divLogin.jsp代码如下:

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib uri="/struts-tags" prefix="struts" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<struts:head theme="xhtml"/>  
<sx:head parseContent="true"/>
<div class="div" id="loginDiv">
  <div id=errorDiv>
  </div>
  <struts:form name="divLoginForm" id="divLoginForm">
  <struts:label label=" 请输入用户名密码:"></struts:label>
  <struts:textfield name="username" label="账号" value="helloween"></struts:textfield>
  <struts:password name="password" label="密码" value="1234" title="1234">
  </struts:password>
  <struts:url action="divLogin!login" id="divLoginUrl" >
  </struts:url>
   
  <struts:submit value="登录" formId="divLoginForm" theme="ajax" href="%{divLoginUrl}"
  targets="loginSuccessDiv" executeScripts= "true" />  
   
  </struts:form>
  
</div>
<div id="loginSuccessDiv" class="div" style="display:none;">
</div>

divLoginAction.java代码如下:
package com.struts2.action;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
public class DivLoginAction extends ActionSupport{
private String username;
private String password;

public String execute()
{
return "input";
}

public String login()
{
if("helloween".equals(username)&& "1234".equals(password))
{
ServletActionContext.getRequest().getSession(true).setAttribute("username", username);
ServletActionContext.getRequest().setAttribute("status","success");
}
else
{
ServletActionContext.getRequest().setAttribute("status","failed");
}
return "script";
}

public String logout()
{
ServletActionContext.getRequest().getSession(true).removeAttribute("username");
ServletActionContext.getRequest().setAttribute("status","logout");
return "script";
}

}


divLoginScript.jsp代码如下:
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ taglib uri="/struts-tags" prefix="struts" %>
<struts:bean id="date" name="java.util.Date"></struts:bean>
<struts:if test="%{#request.status == 'success'}">
  欢迎你,<struts:property value="#session.username"/>.登录时间:<struts:date name="%{#date}"/>
  <struts:url action="divLogin!logout" id="divLogoutUrl"></struts:url>
  <struts:a href="%{#divLogoutUrl}" theme="ajax" executeScript="true">
  </struts:a>
  <script>
  document.getElementById('errorDiv').innerHTML ='';
  //将error置空


  document.getElementById('loginDiv').style.display ='none';
  //将登录框隐藏
  document.getElementById('loginSuccessDiv').style.display ='';
  //现实成功信息
  </script>
</struts:if>
<struts:elseif test="%{#request.status=='failed'}">
<script>
document.getElementById('errorDiv').innerHTML = "登录失败。错误的用户名密码。";
</script>
</struts:elseif>
<struts:else>
  <script>
  document.getElementById('loginDiv').style.display ='';
  //现实登录框
  document.getElementById('loginSuccessDiv').innerHTML = '';
  //置空成功信息
document.getElementById('loginSuccessDiv').style.display ='none';
  //隐藏成功信息
  </script>
</struts:else>

struts.xml配置如下:

<action name="divLogin" class="com.struts2.action.DivLoginAction">
  <result name="input">/divLogin.jsp</result>
  <result name="script">/divLoginScript.jsp</result>
  </action>



上面是相关的全部代码,点divLogin.jsp界面上的登陆按钮,没有反应。没用调用action,不知道为什么?
请高人帮忙看一下到底是什么原因。谢谢。

[解决办法]
<struts:form name="divLoginForm" id="divLoginForm">
为什么没有指定action呢
[解决办法]
<struts:form action= "divLoginForm " id= "divLoginForm ">

[解决办法]
肯定是有js错了吧,改下ie的配置,让它弹出来js错误信息,把禁用脚本调试去了,就可以看到是哪行出错了
[解决办法]

探讨
肯定是有js错了吧,改下ie的配置,让它弹出来js错误信息,把禁用脚本调试去了,就可以看到是哪行出错了

[解决办法]
探讨
submit中对调用 <struts:url action="divLogin!login" id="divLoginUrl" >
url中有action啊, 还需要在<struts:form 中增加action吗?

[解决办法]
探讨
submit中对调用 <struts:url action="divLogin!login" id="divLoginUrl" >
url中有action啊, 还需要在<struts:form 中增加action吗?

热点排行