Struts登录Demo提交报错及Jquery UI拖拽容器不滚动问题求助
Hey there, let's break down and solve your two separate issues step by step!
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
scrolloption totrue(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
overflowproperty set to enable scrolling:#your-sortable-container { height: 400px; overflow-y: auto; /* Shows vertical scrollbar when content overflows */ }
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 yourLoginActionclass (check deployment paths below).NoActionMappingFound: Yourstruts-config.xmldoesn't map the form's action URL to an Action class.InvalidActionForm: Mismatch between yourUserFormand the form fields inlogin.jsp.
Step 2: Verify Struts Configuration Files
struts-config.xml
- Ensure your
<form-bean>maps correctly toUserForm:<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:
Note: If you don't need form validation, set<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>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
srcfolder (so compiled.classfiles are deployed toWEB-INF/classes). - The
WEB-INFfolder in your deployed Tomcat directory containsstruts-config.xml,web.xml, and the compiled class files forLoginActionandUserForm. - The form in
login.jspuses the correct action URL (e.g.,<form action="login.do" method="post">) and field names matchUserFormproperties.
内容的提问来源于stack exchange,提问作者LuciferNoSad

