You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Struts登录Demo提交报错及Jquery UI拖拽容器不滚动问题求助

Hey there, let's break down and solve your two separate issues step by step!

Issue 1: jQuery UI Draggable Can't Scroll Sortable Container

Since you're running on Tomcat 8 and Java 9, these backend techs don't directly affect frontend jQuery UI behavior—so let's focus on frontend configurations:

  • Check jQuery & jQuery UI Version Compatibility: Older versions of jQuery UI might have bugs with scrollable sortable containers. Make sure you're using compatible versions (e.g., jQuery 3.x paired with jQuery UI 1.12.x).
  • Enable Scroll in Sortable Configuration: Explicitly set the scroll option to true (it's enabled by default, but sometimes needs explicit declaration) and tweak scroll sensitivity/speed if needed:
    $("#your-sortable-container").sortable({
      scroll: true,
      scrollSensitivity: 80, // Adjust based on your needs
      scrollSpeed: 15       // Controls how fast the container scrolls
    });
    
  • Validate Container CSS: Ensure your sortable container has a fixed height and overflow property set to enable scrolling:
    #your-sortable-container {
      height: 400px;
      overflow-y: auto; /* Shows vertical scrollbar when content overflows */
    }
    
Issue 2: Struts Login Demo Returns ERROR on Submit

Let's troubleshoot this by checking key files and configurations, starting with the most common culprits:

Step 1: First, Check Console Error Details

The console error is your biggest clue! Common errors include:

  • ClassNotFoundException: Means Tomcat can't find your LoginAction class (check deployment paths below).
  • NoActionMappingFound: Your struts-config.xml doesn't map the form's action URL to an Action class.
  • InvalidActionForm: Mismatch between your UserForm and the form fields in login.jsp.

Step 2: Verify Struts Configuration Files

struts-config.xml

  • Ensure your <form-bean> maps correctly to UserForm:
    <form-beans>
      <form-bean name="userForm" type="com.yourpackage.UserForm" />
    </form-beans>
    
  • Confirm your <action> has proper mappings, including input destination and forwards for success/error:
    <action-mappings>
      <action path="/login" 
              type="com.yourpackage.LoginAction" 
              name="userForm" 
              scope="request" 
              validate="true" 
              input="/login.jsp">
        <forward name="success" path="/success.jsp" />
        <forward name="error" path="/error.jsp" />
      </action>
    </action-mappings>
    
    Note: If you don't need form validation, set validate="false" to skip the validation step.

web.xml

Make sure the Struts ActionServlet is configured correctly:

<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>
  <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.do</url-pattern>
</servlet-mapping>

Step 3: Validate LoginAction & UserForm Code

UserForm.java

Ensure it extends ActionForm and has proper getters/setters for your form fields:

package com.yourpackage;

import org.apache.struts.action.ActionForm;

public class UserForm extends ActionForm {
  private String username;
  private String password;

  // Getters and Setters
  public String getUsername() { return username; }
  public void setUsername(String username) { this.username = username; }
  public String getPassword() { return password; }
  public void setPassword(String password) { this.password = password; }
}

LoginAction.java

Make sure it extends Action and returns the correct forward based on login logic:

package com.yourpackage;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class LoginAction extends Action {
  @Override
  public ActionForward execute(ActionMapping mapping, ActionForm form,
                               HttpServletRequest request, HttpServletResponse response) throws Exception {
    UserForm userForm = (UserForm) form;
    
    // Replace with your actual login validation logic
    if ("admin".equals(userForm.getUsername()) && "admin123".equals(userForm.getPassword())) {
      return mapping.findForward("success");
    } else {
      request.setAttribute("errorMsg", "Invalid username or password");
      return mapping.findForward("error");
    }
  }
}

Step 4: Check Eclipse Deployment Setup

From your Eclipse path screenshot, confirm:

  • Your project's Deployment Assembly includes the src folder (so compiled .class files are deployed to WEB-INF/classes).
  • The WEB-INF folder in your deployed Tomcat directory contains struts-config.xml, web.xml, and the compiled class files for LoginAction and UserForm.
  • The form in login.jsp uses the correct action URL (e.g., <form action="login.do" method="post">) and field names match UserForm properties.

内容的提问来源于stack exchange,提问作者LuciferNoSad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:06:22