2 thepromonkeyof heluo ThePromonkeyOf_HeLuo 于 2016.01.18 17:28 提问

Struts2框架,调用action出错404

struts2配置文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">


<!-- 用户登录 -->

/admin.jsp
/error.jsp
/login.jsp

    <action name="rlogin" class="action.Rlogina">
        <result name="radmin">/back/admin.jsp</result>
        <result name="error">/back/error.jsp</result>
        <result name="student">/back/error.jsp</result>
    </action>

    <action name="mana"  class="action.Mana">
        <result name="gong">/back/gong.jsp</result> 
        <result name="shib">/back/shib.jsp</result>
    </action>
</package>
<constant name="struts.i18n.encoding" value="gb2312"></constant>
<constant name="struts.multipart.saveDir" value="/tmp"></constant>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />

jsp:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>


Tmall is first
    <style type="text/css">
body{
    background-image:url("imag/desktop.jpg");
    background-repeat:no-repeat;
}

#right{
margin-right:200px;
background:#FFCBAA;
height:700px;
width:1300px;
float:right;
}



管理员辛苦了!
<div id="right">

******

  用户ID
   用户名
  密 码:

    <s:submit value="查询用户" method="select" />
    <s:submit value="删除用户" method="delete" />
    <s:submit value="修改用户" method="update" />
    </s:form>******
</div>


Action:
package action;
import java.util.*;
import model.*;
import dao.*;
import com.opensymphony.xwork2.*;

public class Mana extends ActionSupport{
private Ruser ruser;
private Login login;
private String message;

public String select() throws Exception{
    Rudao rudao = new Rudao();
    Login onelog=rudao.select(login.getName());
    if(onelog==null){
        this.setMessage("不存在该用户!");
        return "shib";                                              
    }
    Map request=(Map) ActionContext.getContext().get("request");    
    request.put("onelog", onelog);
    return "gong";
}

public String update() throws Exception{
    Rudao rudao = new Rudao();
    Login b=rudao.select(login.getName());
    if(b==null){
        this.setMessage("要修改的用户不存在!");
        return "shib";
    }
    b.setId(login.getId());
    b.setName(login.getName());
    b.setPassword(login.getPassword());

    rudao.update(b);
    this.setMessage("修改成功!");
    return "gong";
}

public String delete() throws Exception{
    Rudao rudao = new Rudao();
    Login bo=rudao.select(login.getName());
    if(bo==null){             //首先判断是否存在该用户
        this.setMessage("要删除的用户不存在!");
        return "shib";
    }
    rudao.delete(login.getName());
    this.setMessage("删除成功!");
    return "gong";
}


public Ruser getRuser() {
    return ruser;
}
public void setRuser(Ruser ruser) {
    this.ruser = ruser;
}

public Login getLogin() {
    return login;
}
public void setLogin(Login login) {
    this.login = login;
}

public String getMessage() {
    return message;
}
public void setMessage(String message) {
    this.message = message;
}

}

控制台提示:
Could not find action or result: /login01/mana.action
No result defined for action action.Mana and result input图片说明

3个回答

qq_16717565
qq_16717565   2016.01.18 17:51

struts2.xml 配置文件中的action元素下的class属性,不应该是类吗?

qq_16717565
qq_16717565   2016.01.18 17:52

如果要具体到哪个方法的话,action 有method这个属性.

Royal_lr
Royal_lr   Ds   Rxr 2016.01.19 10:04

发请求时没有指定方法,,默认执行execute()方法返回success,,而你的配置文件中又没有result为success,所以会抛异常

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!