这是我的struts.xml
<struts>
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
<action name="reg" class="action.StudentAction">
<result name="success">register-success.jsp</result>
<result name="error">register-error.jsp</result>
</action>
<action name="login" class="action.LoginAction" method="execute">
<result name="success">hello.jsp</result>
<result name="input">login.jsp</result>
<result name="error">login.jsp</result>
</action>
</package>
</struts>
这是我的userDao
package action;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import util.HibernateService;
import util.Student;
public class UserDao {
public boolean find(String username,String password)
{
Session s=HibernateService.getSession();
String q="select * from student where username='"+username+"' and
password='"+password+"'";
System.out.println(q);
Query query=s.createQuery(q);
Iterator<Student> it=query.iterate();
List<Student> list=query.list();
if(list.size()>0)
{
s.close();
return true;
}
s.close();
return true;
}
}
这是我的LoginAction
package action;
import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import util.HibernateService;
public class LoginAction extends ActionSupport{
private String username;
private String password;
UserDao dao=new UserDao();
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;
}
public void validate()
{
if(username==null)
this.addFieldError("username", "USERNAME is required");
if(password==null)
this.addFieldError("password", "PASSWORD is required");
}
public String execute() throws Exception {
if(dao.find(getUsername(), getPassword()))
return SUCCESS;
else
{
this.addActionError("Invalid Username or Password");
return ERROR;
}
}
}
我收到错误HTTP状态404 - 没有为动作action.LoginAction和结果输入定义结果。 此外,我已经看到许多解决这个问题的方法,即添加第二行,但它仍然无法正常工作 有什么建议? 注册页面工作正常。