weixin_43170659
weixin_43170659
2020-07-05 22:52

.No result defined for action xxx.xxx.xxx and result input 错误

  • java
  • tomcat
  • struts
  • java-ee
  • eclipse

错误信息
警告: Could not find action or result: /zxc/addStu.action
No result defined for action org.easybooks.zxc.action.StudentAction and result input - action - file:/C:/Users/lifutao/eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/zxc/WEB-INF/classes/struts.xml:17:86
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:371)

struts.xml

<?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">
<struts>

<package name="default" extends="struts-default" >

<action name="showAll" class="org.easybooks.zxc.action.ScoreAction" method="showAll">
<result name="result">/scoreManage.jsp</result>
</action>
<action name="queSco" class="org.easybooks.zxc.action.ScoreAction" method="queSco">
<result name="result">/showAll.jsp</result>
</action>

<!-- 录入学生 -->
<action name="addStu" class="org.easybooks.zxc.action.StudentAction" method="addStu">
<result name="result">/studentManage.jsp</result>
</action>
</package>

StudentAction.java

package org.easybooks.zxc.action;
import java.sql.*;
import java.util.*;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.views.freemarker.tags.SetModel;
import org.easybooks.zxc.jdbc.*;
import org.easybooks.zxc.vo.*;
import com.opensymphony.xwork2.*;

import oracle.net.aso.r;

import java.io.*;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
public class StudentAction extends ActionSupport{
private String xm;
private String msg;
private Student student;
private Score score;
private File photo;
public String addStu() throws Exception{
    String sql="select * from xs where xm='''+getXm()+'''";
    Statement stmt=OrclConn.conns.createStatement();
    ResultSet rs=stmt.executeQuery(sql);
    if(rs.next()) {
        setMsg("该学生已经存在");
        return "result";
    }
    StudentJdbc studentJ=new StudentJdbc();
    Student stu=new Student();
    stu.setXm(getXm());
    stu.setXb(student.getXb());
    stu.setCssj(student.getCssj());
    stu.setKcs(student.getKcs());
    stu.setBz(student.getBz());
    if(this.getPhoto()!=null)
    {
        FileInputStream fis=new FileInputStream(this.getPhoto());
        byte[] buffer=new byte[fis.available()];
        fis.read(buffer);
        stu.setZp(buffer);
    }
    if(studentJ.addStudent(stu)!=null)
    {
        setMsg("添加成功 ");
        Map request=(Map)ActionContext.getContext().get("request");
        request.put("student", stu);


    }else
        setMsg("添加失败");

    return "result";    
}
public String getImage() throws Exception{
    HttpServletResponse response=ServletActionContext.getResponse();
    StudentJdbc studentJ=new StudentJdbc();
    student=new Student();
    student.setXm(getXm());
    byte[] img=studentJ.getStudentZp(student);
    response.setContentType("image/jpeg");
    ServletOutputStream os=response.getOutputStream();
    if(img!=null&&img.length!=0) {
        for(int i=0;i<img.length;i++) {
            os.write(img[i]);
        }
        os.flush();
    }

    return NONE;
}
public String delStu() throws Exception{
    boolean exist=false;
    String sql="select * from xs where xm='''+getXm()+'''";
    Statement stmt=OrclConn.conns.createStatement();
    ResultSet rs=stmt.executeQuery(sql);
    if(rs.next())
    {
        exist=true;
    }
    if(exist)
    {
        StudentJdbc studentJ=new StudentJdbc();
        Student stu=new Student();
        stu.setXm(getXm());
        if(studentJ.delStudent(stu)!=null)
        {
            setMsg("删除成功");
        }
        else 
            setMsg("删除失败 请检查权限"); 
    }else {
        setMsg("该学生不存在");
    }
    return "result";
}
public String queStu() throws Exception{
    boolean exist=false;
    String sql="select * from xs where xm='''+getXm()+'''";
    Statement stmt=OrclConn.conns.createStatement();
    ResultSet rs=stmt.executeQuery(sql);
    if(rs.next())
    {
        exist=true;
    }
    if(exist)
    {
        StudentJdbc studentJ=new StudentJdbc();
        Student stu=new Student();
        stu.setXm(getXm());
        if(studentJ.showStudent(stu)!=null) {
            setMsg("查找成功");
            Map request=(Map)ActionContext.getContext().get("request");
            request.put("student", stu);
            ScoreJdbc scoreJ=new ScoreJdbc();
            Score sco=new Score();
            sco.setXm(getXm());
            List<Score> scoList=scoreJ.showScore(sco);
            request.put("scoreList", scoList);
        }
        else setMsg("查找失败 请检查权限");
    }else setMsg("该学生不存在");
return "result";
}
public String updStu() throws Exception{
    StudentJdbc studentJ=new StudentJdbc();
    Student stu=new Student();
    stu.setXm(getXm());
    stu.setXb(student.getXb());
    stu.setCssj(student.getCssj());
    stu.setKcs(student.getKcs());
    stu.setBz(student.getBz());
    if(this.getPhoto()!=null) {
        FileInputStream fis=new FileInputStream(this.getPhoto());
        byte[] buffer=new byte[fis.available()];
        fis.read(buffer);
        stu.setZp(buffer);
    }
    if(studentJ.updateStudent(stu)!=null )
    {
        setMsg("更新成功 ");
        Map request=(Map)ActionContext.getContext().get("request");
        request.put("student", stu);


    }else
        setMsg("更新失败");

    return "result";    
}





public String getXm() {
    return xm;
}
public void setXm(String xm) {
    this.xm = xm;
}
public String getMsg() {
    return msg;
}
public void setMsg(String msg) {
    this.msg = msg;
}
public Student getStudent() {
    return student;
}
public void setStudent(Student student) {
    this.student = student;
}
public Score getScore() {
    return score;
}
public void setScore(Score score) {
    this.score = score;
}
public File getPhoto() {
    return photo;
}
public void setPhoto(File photo) {
    this.photo = photo;
}
}

studentManage.jsp

<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>    
<html>
<head>
<title>学生管理</title>
</head>
<body bgcolor="D9DFAA">
<s:set name="student" value="#request.student"/>
<s:form name="frm" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>
<table>

<tr>
    <td>姓 名:</td><td><input type="text" name="xm" value="<s:property value="#student.xm"/>"/></td>
</tr>

<tr>
    <td><s:radio list="{'男','女'}" label="性别" name="student.xb" value="#student.xb"/></td>
</tr>

<tr>
    <td>出生年月:</td><td><input type="text" name="student.cssj" value="<s:date name="#student.cssj" format="yyyy-MM-dd"/>"/></td>
</tr>

<tr>
<s:file name="photo" accept="image/*" label="照片" onchange="document.all['image'].src=this.value;"/>
</tr>

<tr>
<td></td>
<td><img src="getImage.action?xm=<s:property value="#student.xm"/>" width="90" height="120"/></td>
</tr>

<tr>
<td></td>
<td>
    <input name="btn1" type="button" value="录入" onclick="add()">
    <input name="btn2" type="button" value="删除" onclick="del()">
    <input name="btn3" type="button" value="更新" onclick="upd()">
    <input name="btn4" type="button" value="查询" onclick="que()">
    </td>
    </tr>
</table>
</td>

<td>
    <table>
        <tr>
    <td>已修课程<input type="text" name="student.kcs" value="<s:property value="#student.kcs"/>"disabled/></td>
</tr>
<tr>

<td align="left">
<table border="1">
<tr bgcolor="#CCCCC0">
<td>课程名</td>
<td align="center">成绩</td>
</tr>
<s:iterator value="#request.scoreList" id="sco">
<tr>
    <td><s:property value="#sco.kcm"/>&nbsp;</td>
<td align="center"><s:property value="#sco.cj"/></td>
</tr>
</s:iterator>   
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<s:property value="msg"/>
</s:form>
</body>
</html>


<script type="text/javascript">
function add() {
    document.frm.action="addStu.action";
    document.frm.submit();
}
function del() {
    document.frm.action="delStu.action";
    document.frm.submit();
}
function upd() {
    document.frm.action="updStu.action";
    document.frm.submit();
}
function que() {
    document.frm.action="queStu.action";
    document.frm.submit();
}
</script>
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答