兄弟初学,做一个登陆界面(adminlogin.jsp),通过这个jsp触发一个struts的action,adminlogin.jsp如下:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-nested" prefix="nested" %><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title><bean:message key="adminloginPage.title"/></title>
    <link href="styles/ezlife.css" rel="stylesheet" type="text/css">
</head>
<body>
        <FORM ACTION="/admin_login.do" METHOD="post" NAME="adminloginForm">    
<table width="30%" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
      <td colspan="2" bgcolor="#CCFF33" class="warning"><bean:message key="adminloginPage.adminloginForm.warning"/></td>
    </tr>
    <tr>
      <td colspan="2" >&nbsp;</td>
    </tr>
    <tr>
      <td><div align="right"><bean:message key="adminloginPage.adminloginForm.admin_id"/></div></td>
      <td><div align="right"><input type="text" name="admin_id" size="30" maxlength="30" tabindex="1"onKeyPress="return handleEnter(this, event)" /></div></td>
    </tr>
    <tr>
      <td><div align="right"><bean:message key="adminloginPage.adminloginForm.admin_passwd"/> </div></td>
      <td><div align="right"><input type="password" name="p_request" size="30" maxlength="30" tabindex="2" onKeyPress="return handleEnter(this, event)" /></div></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td align="right"><input type="button" name="Submit" value="<bean:message key="adminloginPage.adminloginForm.buttonlogon"/>" onClick="JavaScript:loginSubmit();" tabindex="3" /></td>
    </tr>
    <input type="hidden" name="admin_passwd" value=""> </table>
    <tr>
    <td colspan="2"><div align="center"><html:errors/></div></td>
    </tr>
</FORM>
    <script language="javascript">
    <!--
      window.document.adminloginForm.admin_id.focus();
    //-->
    </script>
<script language="javascript">
<!--
function loginSubmit()
{
var mess = "";
var val = window.document.adminloginForm.admin_id.value;
if ( (val.length==0) || (val==null) || (val=="") )
{
mess = mess + "用户名";
}
var val = window.document.adminloginForm.p_request.value;
if ( (val.length==0) || (val==null) || (val=="") )
{
if (mess!="") mess = mess + "和口令";
else mess = "口令"
}
if (mess!="")
{
mess = "请输入" + mess;
alert(mess);
return false;
}

window.document.adminloginForm.admin_passwd.value = document.adminloginForm.p_request.value;
window.document.adminloginForm.submit();
}

//to submit form on hitting enter
function handleEnter (field, event) 
{
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if (keyCode == 13) 
  {
   loginSubmit();
  } 

//-->
</script>     
        <p>
        <%@ include file="/include/footer.jspf" %>
        </p>
</body>
</html>--------------------------------

解决方案 »

  1.   

    struts-config.xml如下:<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
    <struts-config>
      <data-sources>
      </data-sources>
      <!-- (1)*********数据源*********  (2)*********表单定义********* -->
      <form-beans>
        <!-- 数据管理员登陆表单 -->
        <form-bean name="adminloginForm" type="org.apache.struts.validator.DynaValidatorForm">
          <form-property name="admin_id" type="java.lang.String" size="30"/>
          <form-property name="admin_passwd" type="java.lang.String" size="30"/>
        </form-bean>
      </form-beans>
      <!-- (3)*********全局例外********* -->
      <global-exceptions>
      </global-exceptions>
      <!-- (4)*********全局转移********* -->
      <global-forwards>
        <forward name="adminlogin" path="/adminlogin.jsp"/>
      </global-forwards>
      <!-- (5)*********行为映射********* -->
      <action-mappings>
        <action name="adminloginForm" path="/admin_login" type="com.dmaple.ezlife.web.action.AdminLoginAction" scope="request" validate="true" input="/adminlogin.jsp">
          <forward name="success" path="/adminopmenu.jsp"/>
        </action>
      </action-mappings>
      <controller>
        <set-property property="processorClass" value="org.springframework.web.struts.DelegatingTilesRequestProcessor"/>
      </controller>
      <message-resources parameter="MessageResources"/>
      <!-- (8)*********Plugin定义,包括Validation********* -->
      <plug-in className="org.apache.struts.tiles.TilesPlugin">
        <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/>
        <set-property property="moduleAware" value="true"/>
      </plug-in>
      <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
        <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
      </plug-in>
      <!-- Spring Plugin定义 -->
      <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation" value="/WEB-INF/action-servlet.xml,/WEB-INF/applicationContext.xml"/>
      </plug-in>
    </struts-config>
    ------------------------------------------------------------------
    web.xml:
    <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE web-app
      PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app>
     <!-- ======================== 配置Struts ============================== -->
      <servlet>
        <!--控制器ActionServlet的配置-->
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <!--Struts的配置文件-->
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <init-param>
          <!--Struts的调试级别-->
          <param-name>debug</param-name>
          <param-value>2</param-value>
        </init-param>
        <init-param>
          <param-name>detail</param-name>
          <param-value>2</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
      </servlet>  <!--配置ActionServlet的启动URL模式-->
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>  <!--配置Struts的Tag Lib-->
      <taglib>
        <taglib-uri>/tags/struts-bean</taglib-uri>
        <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
      </taglib>  <taglib>
        <taglib-uri>/tags/struts-html</taglib-uri>
        <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
      </taglib>  <taglib>
        <taglib-uri>/tags/struts-logic</taglib-uri>
        <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
      </taglib>  <taglib>
        <taglib-uri>/tags/struts-nested</taglib-uri>
        <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
      </taglib>  <taglib>
        <taglib-uri>/tags/struts-tiles</taglib-uri>
        <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
      </taglib>
      <!--
      <taglib>
        <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
        <taglib-location>/WEB-INF/c.tld</taglib-location>
      </taglib>  <taglib>
        <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
        <taglib-location>/WEB-INF/fmt.tld</taglib-location>
      </taglib>  <taglib>
        <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
        <taglib-location>/WEB-INF/sql.tld</taglib-location>
      </taglib>  <taglib>
        <taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
        <taglib-location>/WEB-INF/x.tld</taglib-location>
      </taglib>
      -->
    </web-app>
    --------------------------------------------------------------------
    问题是我每次输入完口令密码后都会报如下错误;
    HTTP Status 404 - /admin_login.do--------------------------------------------------------------------------------type Status reportmessage /admin_login.dodescription The requested resource (/admin_login.do) is not available.
    --------------------------------------------------------------------------------Apache Tomcat/5.5.17俺没经验,也不知道该怎么调试这样的程序,直观的感觉是action mapping有问题,可是我怎么也找不到错在哪里,应该还没有到Action的执行以及后台的Hibernate处理.
      

  2.   

    FORM ACTION="/admin_login.do"你如果用的是普通html表单标记,action=""中要有web项目名称
    如果是struts标签
    <html:form action="/admin_login.do"可以这样
      

  3.   

    谢谢这位兄弟,按照你的意见改了,还是有以下错误,第一次调,有什么经验能分享一下吗? Status reportmessage Servlet action is not availabledescription The requested resource (Servlet action is not available) is not available.
      

  4.   

    这是SSH组合到一块的么?
    你可以先只做struts,
    如果没问题,在加spring
      

  5.   

    发现问题了,把log4j.properties从Hibernate的etc目录下copy到/WEB-INF/classes目录下,就可以查看详细的log了,在tomcat的logs\stdout_xxx.log中,这样就可以分析问题了.
    之前失败的原因是一个Hibernate用的POJO数据表的java程序没有个ID提供供setter和getter函数...,另外applicationContent.xml中有些写错了.谢谢!