只是写了一个简单的登录页面:
jsp页面部分代码如下:
 <body>
  <s:property value="tip"/>
    <s:form action="login" method="post"> 
   <s:textfield name="personId" key="username"></s:textfield>
      <s:password name="password" key="password"></s:password>
      <input name="personType" type="radio" value="11"/>学生
       <input name="personType" type="radio" value="12"/>教师
    
      <s:submit value="submit"></s:submit>
    </s:form>
  </body>Action代码如下:
package teacher.action;import teachinves.db.loginDAO;import com.bean.Users;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{
      private String personId;
      private String password;
      private int personType;
      private String tip;
public String getPersonId() {
return personId;
}
public void setPersonId(String personId) {
this.personId = personId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getTip() {
return tip;
}
public void setTip(String tip) {
this.tip = tip;
}
      public String execute()throws Exception{
       Users users=new Users();
       users.setPersonId(personId);
       users.setPassword(password);
       users.setPersonType(personType);
       loginDAO LD=new loginDAO();
       boolean flag=LD.login(users);
       if(flag){
       ActionContext.getContext().getSession().put("personId", personId);
       return "success";
       }else{
       this.setTip(this.getText("login.failed"));
       return "input";
       }
       
       
      }
public int getPersonType() {
return personType;
}
public void setPersonType(int personType) {
this.personType = personType;
}
}数据库查询
:package teachinves.db;import java.sql.PreparedStatement;
import java.sql.ResultSet;import DBConn.Odb;import com.bean.Users;public class loginDAO {
   Odb odb=new Odb();
public boolean login(Users users) {
boolean flag=false;
String sql=null;
PreparedStatement ps=null;
try{
if(users.getPersonType()==11) sql="select vstudentid,vpassword from BASIC_INFO_STUDENT where vstudentid='"+users.getPersonId()+"' and vpassword='"+users.getPassword()+"'";
if(users.getPersonType()==12) sql="select vteacherid,vpassword from BASIC_INFO_TEACHER where vteacherid='"+users.getPersonId()+"' and vpassword='"+users.getPassword()+"'";
ps=odb.getConnection().prepareStatement(sql);
ResultSet rs=ps.executeQuery();
if(rs.next()){
flag=true;

}
}catch (Exception e){
e.printStackTrace();
}
return flag;
}

   
}sstruts配置:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<include file="struts-default.xml"></include>
<package name="struts2" extends="struts-default">
<action name="login" class="teacher.action.LoginAction" >
  <result name="success">/student/index/index.jsp</result>
  <result name="input">/login.jsp</result>
</action>
  </package>
</struts>
在登录时后台不报错,但会在页面显示一下的错误
HTTP Status 404 - No result defined for action teacher.action.LoginAction and result success--------------------------------------------------------------------------------type Status reportmessage No result defined for action teacher.action.LoginAction and result successdescription The requested resource (No result defined for action teacher.action.LoginAction and result success) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.29

解决方案 »

  1.   

    <result name="success">/student/index/index.jsp</result>
    /student/index/index.jsp  确定有这路径?
      

  2.   

     <s:textfield name="personId" key="username"></s:textfield>
      <s:password name="password" key="password"></s:password>
    没看到你的实体类
      比如你的实体类为quest
       <s:textfield name="quest.username" >这样写就可以
      
      

  3.   

    没找到这个action类,看有没有编译到指定的class文件目录的
      

  4.   

    <body>
      <s:property value="tip"/>
      <s:form action="login" method="post">  //action="login.action"
      <s:textfield name="personId" key="username"></s:textfield>
      <s:password name="password" key="password"></s:password>
      <input name="personType" type="radio" value="11"/>学生
      <input name="personType" type="radio" value="12"/>教师
        
      <s:submit value="submit"></s:submit>
      </s:form>
      </body>
      

  5.   

    <result name="success">/student/index/index.jsp</result>
    换成一个简单的,放在webroot下面的jsp看看还有就试试 密码 用户名不正确的情况下 可以调到login.jsp不 ?
    <result name="input">/login.jsp</result>
      

  6.   

    <package name="struts2" extends="struts-default">里加上namespace="/"试试
      

  7.   

    这个可能是你发布到tomcat里的工程跟你当前的项目工程不一致了,你可以redeploy一下。
      

  8.   

    <action name="login" class="teacher.action.LoginAction" >
      <result name="success">/student/index/index.jsp</result>
      <result name="input">/login.jsp</result>
    </action>改成这样试试<action path="/login"
    name="login"
    type="teacher.action.LoginAction"
    scope="request"
    input="/login.jsp">
    <forward name="success" path="/student/index/index.jsp"/>
    </action>
      

  9.   

    里面的path、type都说没定义,这个怎么解决呢
      

  10.   

    你调试一下?或者重新编译一下,感觉你的配置的没有问题。
    或者是不是你在web.xml中配置过滤器的事情?你只是过滤.action么?
      

  11.   

    是只过滤了.action了,我重新建了个工程,把代码复制粘贴了一遍就是可以的
      

  12.   

    是你的Action类没有,所以报错!