2012-09-10 41 views
-2

我试图实现这个系统:http://en.pudn.com/downloads108/sourcecode/java/jsp/detail446536_en.html执行投票系统struts,mysql

但我得到404登录错误。我输入url:localhost:8080/voting /。 输入用户和密码后,正确的,我提交表单,并得到404错误:

http://localhost:8080/voting/login.html?method=login 


HTTP Status 404 - 

type Status report 

message 

description The requested resource() is not available. 

Apache Tomcat/7.0.29 

我正确配置数据库。 我不明白是什么问题? 请有人帮忙吗?

有在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-source type="org.apache.commons.dbcp.BasicDataSource"> 
<set-property property="url" value="jdbc:mysql://localhost:3306/vote"/> 
<set-property property="driverClassName" value="com.mysql.jdbc.Driver"/> 
<set-property property="username" value="root"/> 
<set-property property="password" value="123"/> 
<set-property property="maxCount" value="50" /> 
<set-property property="minCount" value="30" /> 
<set-property property="maxActive" value="10" /> 
<set-property property="maxWait" value="5000" /> 
<set-property property="defaultAutoCommit" value="false" /> 
</data-source> 
</data-sources> 
<form-beans > 
<form-bean name="loginForm" type="edu.school.voting.control.LoginForm" /> 
<form-bean name="votesForm" type="edu.school.voting.control.VotesForm" /> 
<form-bean name="optionsForm" type="edu.school.voting.control.OptionsForm" /> 

</form-beans> 

<global-exceptions /> 
<global-forwards /> 
<action-mappings > 
<action 
    attribute="loginForm" 
    input="/login.jsp" 
    name="loginForm" 
    parameter="method" 
    path="/login" 
    scope="request" 
    type="edu.school.voting.control.LoginAction"> 
    <forward name="success" path="/votes.jsp" contextRelative="true" /> 
    <forward name="admin" path="/admin/admin.jsp" /> 
    <forward name="error" path="/error.jsp" /> 
    <forward name="input" path="/login.jsp" /> 
    <forward name="showuser" path="/admin/user/showuser.jsp" /> 
    <forward name="amenduser" path="/admin/user/edituser.jsp" /> 
    <forward name="findusers" path="/login.html?method=list" /> 
    <forward name="createuser" path="/admin/user/adduser.jsp" /> 
    </action> 
    ...................................... 

从login.jsp的代码:

<form id="loginForm" name="loginForm" method="post" action="<%=request.getContextPath()%>/login.html?method=login"> 
      <table width="240" height="165" border="0" cellpadding="0" cellspacing="0"> 
       <tr> 
       <td align="center" valign="middle"><table width="230" border="0" align="center" cellpadding="5" cellspacing="0" class="p1"> 
        <tr> 
        <td align="right">&nbsp;</td> 
        <td>&nbsp;</td> 
        </tr> 
        <tr> 
        <td width="45" align="right">ID:</td> 
        <td width="165"><input class="inputPSW" name="account" id="account" type="text" maxlength="16"></td> 
        </tr> 
        <tr> 
        <td align="right">Password:</td> 
        <td><input class="inputPSW" id="pwd" name="pwd" type="password" maxlength="16"></td> 
        </tr> 
        <tr> 
        <td colspan="2" align="center"> 
        <img onClick="return CheckForm();" src="<%=request.getContextPath()%>/images/login/bn_login1.gif" id="Image1" onMouseOver="MM_swapImage('Image1','','<%=request.getContextPath()%>/images/login/bn_login2.gif',1)" onMouseOut="MM_swapImgRestore()">&nbsp; 
        <img onClick="return resetBt();" src="<%=request.getContextPath()%>/images/login/bn_reset1.gif" id="Image2" onMouseOver="MM_swapImage('Image2','','<%=request.getContextPath()%>/images/login/bn_reset2.gif',1)" onMouseOut="MM_swapImgRestore()"> 
         <input name="CheckLogin" type="hidden" id="CheckLogin" value="True">      </td> 
        </tr> 
       </table></td> 
       </tr> 
      </table> 
      </form> 

这是我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
<servlet> 
<servlet-name>action</servlet-name> 
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class> 
<init-param> 
    <param-name>config</param-name> 
    <param-value>/WEB-INF/struts-config.xml</param-value> 
</init-param> 
<init-param> 
    <param-name>debug</param-name> 
    <param-value>3</param-value> 
</init-param> 
<init-param> 
    <param-name>detail</param-name> 
    <param-value>3</param-value> 
</init-param> 
<load-on-startup>0</load-on-startup> 
</servlet> 
<servlet-mapping> 
<servlet-name>action</servlet-name> 
<url-pattern>*.html</url-pattern> 
</servlet-mapping> 

<filter> 
<filter-name>encoding</filter-name> 
<filter-class>edu.school.voting.common.EncodingFilter</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>encoding</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 

<filter> 
<filter-name>safty</filter-name> 
<filter-class>edu.school.voting.common.SaftyFilter</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>safty</filter-name> 
<url-pattern>/admins/*</url-pattern> 
</filter-mapping> 

<welcome-file-list> 
<welcome-file>login.jsp</welcome-file> 
</welcome-file-list> 

</web-app> 

在哪里我做错了吗?

+1

不确定如何提供帮助;日志里有什么?代码是什么?配置?等 –

+0

我希望找到一个曾经尝试过这个应用程序的人,因为重要的是自己试着去理解问题...... – rakela

+0

这可能是由于配置错误导致的。错误http 404意味着资源或方法不可用。显示您的配置的一些片段,这将有助于了解您的问题。 –

回答

0

除非实际将您的动作servlet映射到*.html,否则表单标记中的"action"属性几乎肯定是错误的。如果您使用派遣操作,则操作应该指向您在struts-config文件中配置的操作。

除此之外,为什么不使用任何Struts 1表单标签?他们让事情变得更容易。另外,我建议把你的JSP文件放在WEB-INF之下,这样它们就不能被客户直接访问。

此外,这与Spring MVC,Hibernate或Struts 2无关。

+0

我需要使这个应用程序工作。无论使用哪个框架。你建议我做什么来解决它? – rakela

+0

@rakela您未提供用于诊断问题的信息。 404?您正尝试访问不存在的资源。我不知道你的动作映射是什么。这些标签用于向帖子中添加有关使用什么技术的元数据 - 如果您使用的是Struts 1,而且根据您的指示,使用除Struts 1之外的其他标签标记Struts 1是非常奇怪的。 –