实现投票系统struts,mysql

时间:2012-09-10 21:22:32

标签: struts

我正在尝试实施此系统:http://en.pudn.com/downloads108/sourcecode/java/jsp/detail446536_en.html

但登录时遇到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 :(得分:0)

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

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

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