qcs47122481 2011-11-17 13:46
浏览 229
已采纳

关于struts 页面 404错误!!!!!!!!!!!

struts.xml


    </action>
</package>

spring.xml




index.jsp


请输入以下信息:

您的名字:

您的密码:


URL
http://localhost:8888/EJB3StrutsWeb/getUser!login?userName=ii&userPsw=iii

为什么没进action了??各位大哥们!哪里有问题

  • 写回答

17条回答 默认 最新

  • qq1988627 2011-11-17 15:25
    关注

    [code="java"]
    method 是对应action类下面的方法 一个action 类有多个方法 配置就是 同一个action 也就是class=“相同” method不同



    manager_index.jsp
    /main/index.jsp


    /main/index.jsp


    /main/out.jsp
    /main/out.jsp

    基于json的



    success,id




    success,down




    success




    success



    userAction 类里面

    package byd.action;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.OutputStream;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;

    import jxl.Sheet;
    import jxl.Workbook;

    import byd.entity.BaseBean;
    import byd.entity.LogOut;
    import byd.entity.User;
    import byd.core.BaseAction;
    import byd.core.ExcelExport;
    import byd.core.MyUtils;
    import byd.core.Page;
    import byd.core.RandomUtils;
    import byd.service.ICrudBaseService;

    @SuppressWarnings("serial")
    public class UserAction extends BaseAction{
    private Page page;
    @SuppressWarnings("unchecked")
    private ICrudBaseService baseService;
    private User user;
    private boolean success;
    private Integer id;
    private String userName;
    private String passWord;
    private File upload;
    private String uploadFileName;
    private List<?> list;
    private String downloadFile;
    private String path;
    private String down;

    /**
     * @return the downloadFile
     */
    public String getDownloadFile() {
        return downloadFile;
    }
    
    /**
     * @param downloadFile the downloadFile to set
     */
    public void setDownloadFile(String downloadFile) {
        this.downloadFile = downloadFile;
    }
    
    /**
     * @return the path
     */
    public String getPath() {
        return path;
    }
    
    /**
     * @param path the path to set
     */
    public void setPath(String path) {
        this.path = path;
    }
    
    /**
     * @return the down
     */
    public String getDown() {
        return down;
    }
    
    /**
     * @param down the down to set
     */
    public void setDown(String down) {
        this.down = down;
    }
    
    /**
     * @return the baseService
     */
    @SuppressWarnings("unchecked")
    public ICrudBaseService getBaseService() {
        return baseService;
    }
    
    /**
     * @param baseService the baseService to set
     */
    @SuppressWarnings("unchecked")
    public void setBaseService(ICrudBaseService baseService) {
        this.baseService = baseService;
    }
    
    public String logout(){
        getSession().removeAttribute("user");
        success = true;
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String login(){
        User user = new User();
        user.setUserName(userName);
        user.setPassWord(passWord);
        //bean.setObjCondition(user);
        User _user=null;
        try {
            _user = (User) baseService.queryForObject("User.login",user);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (_user!=null){
            //success=true;
            getSession().setAttribute("user", _user);
            return SUCCESS;
        }else{
            //success=false;
            return INPUT;
        }
    }
    
    @SuppressWarnings("unchecked")
    public String saveUser(){
        try {
            list = baseService.findByModel("User.findByUser", user);
            if(list.size()>0){
                success=false;
            }else{
                id =(Integer)baseService.saveRecord("User.save", user);
                if(id != null){
                    success = true;
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String findAllUser(){
        User user =(User)getSession().getAttribute("user");
        User _user=null;
        page = new Page();
        //System.out.println(user.getRole());
        if(user.getRole().equals("MANAGER")){
            String strCondition = getRequest().getParameter("conditions");
    
            page.setObjCondition(strCondition);
            int start = Integer.parseInt(getRequest().getParameter("start"));
            int limit = Integer.parseInt(getRequest().getParameter("limit"));
            page.setStart(++start);
            page.setLimit(limit = limit ==0 ? 25 : limit);
            try {
                page = baseService.findByPage("User.findByPage", "User.findByCount", page);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }else{
            try {
                 _user = (User) baseService.queryForObject("User.findAll",user);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            List list = new ArrayList();
            list.add(_user);
            page.setRoot(list);
        }
        return SUCCESS;
    }
    
    public String exUser(){
        try{
            page = new Page();
            page.setRoot(baseService.findByList("User.findAll"));
            List<User> list=page.getRoot();
            String rootPath=getSession().getServletContext().getRealPath("/");
            String fileNameString=RandomUtils.generateMixString(8)+".xls";
            downloadFile = rootPath + "main\\root\\"+fileNameString;
            path = "root//"+fileNameString;
            down = new String(path.getBytes(), "utf-8");
            success = MyUtils.delAllFile(rootPath+"main\\root\\");          OutputStream out = new FileOutputStream(downloadFile);
            ExcelExport export=new ExcelExport();
            export.exportExcel("用户信息", list, out);
            //@SuppressWarnings("unused")
            //Long s =System.currentTimeMillis();
            //success=MyUtils.delFile(downloadFile);
            out.close();
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return SUCCESS;
    }
    
    public String findUser(){
        page = new Page();
        try {
            page.setRoot(baseService.findByList("User.findUser"));
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String deleteUser(){
        String strId = getRequest().getParameter("id");
        if(strId != null && !"".equals(strId)){
            user = new User();
            user.setId(Integer.parseInt(strId));
            try {
                success = baseService.deleteRecord(user, "User.deleteById");
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String updateUser() throws Exception{
        user = new User();
        String role=getRequest().getParameter("role");
        if(role.equals("")){
        }else{
            user.setRole(role);
        }
        user.setId(Integer.parseInt(getRequest().getParameter("id")));
        user.setUserName(getRequest().getParameter("userName"));
        user.setPassWord(getRequest().getParameter("passWord"));
        user.setEmplName(getRequest().getParameter("emplName"));
        user.setEmplNo(getRequest().getParameter("emplNo"));
        user.setDeptName(getRequest().getParameter("deptName"));
        user.setDutyName(getRequest().getParameter("dutyName"));
        user.setEmail(getRequest().getParameter("email"));
        user.setPhoneNum(getRequest().getParameter("phoneNum"));
        user.setCompanyName(getRequest().getParameter("companyName"));
        user.setRemark(getRequest().getParameter("remark"));
        success=baseService.updateStatus("User.update", user);
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String saveLogOut(){
        LogOut logOut =new LogOut();
        String strId = getRequest().getParameter("userId");
        String userName=getRequest().getParameter("userName");
        logOut.setUserId(Integer.valueOf(strId));
        logOut.setUserName(userName);
        try {
            id = (Integer)baseService.saveRecord("LogOut.save", logOut);
            if(id!=null){
                success = true;
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return SUCCESS;
    }
    /**
     * @return the baseService
     */
    
    @SuppressWarnings("unchecked")
    public String deleteByUserId(){
        String userId=getRequest().getParameter("id");
        if(userId !=null && !"".equals(userId)){
            user = new User();
            user.setId(Integer.parseInt(userId));
            try {
                success = baseService.deleteRecord(user, "LogOut.deleteById");
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String exportUser(){
        user = new User();
        try{
            if(upload!=null && uploadFileName!=null){
                getResponse().setContentType("text/xml;charset=UTF-8");
                getRequest().setCharacterEncoding("UTF-8");
                String rootPath = getSession().getServletContext().getRealPath("/");
                String newFileName = MyUtils.upload(getUploadFileName(),
                        rootPath, getUpload());
                FileInputStream stream = new FileInputStream(rootPath+newFileName);
                Workbook rwb = Workbook.getWorkbook(stream);
                //int sheetCount = rwb.getNumberOfSheets();
                Sheet shet=rwb.getSheet(0);
                int rows = shet.getRows();
                int clos = shet.getColumns();
                int count=0;
                for(int i=0;i<rows-1;i++){
                    for(int n=0;n<clos;n++){
                        switch(n){
                        case 0:
                            user.setUserName(shet.getCell(0,i+1).getContents());
                            break;
                        case 1:
                            user.setPassWord(shet.getCell(1,i+1).getContents());
                            break;
                        case 2:
                            user.setEmplNo(shet.getCell(2,i+1).getContents());
                            break;
                        case 3:
                            user.setCompanyName(shet.getCell(3,i+1).getContents());
                            break;
                        case 4:
                            user.setEmplName(shet.getCell(4,i+1).getContents());
                            break;
                        case 5:
                            user.setPhoneNum(shet.getCell(5,i+1).getContents());
                            break;
                        case 6:
                            user.setEmail(shet.getCell(6,i+1).getContents());
                            break;
                        case 7:
                            user.setDeptName(shet.getCell(7,i+1).getContents());
                            break;
                        case 8:
                            user.setDutyName(shet.getCell(8,i+1).getContents());
                            break;
                        case 9:
                            user.setRole(shet.getCell(9,i+1).getContents());
                            break;
                        case 10:
                            user.setRemark(shet.getCell(10,i+1).getContents());
                            break;
                        default:
                            break;
                        }
                    }
                    list = baseService.findByModel("User.findByUser", user);
                    if(list.size()>0){
                        success=false;
                    }else{
                        id=(Integer)baseService.saveRecord("User.save", user);
                        if(id!=null){
                            success=true;
                            count=count+1;
                        }
                    }
                    int errorcount = rows-1-count;
                    if(count==rows-1){
                        this.jsonString="{success:true}";
                        getRequest().setAttribute("jsonString", jsonString);
                        return SUCCESS;
                    }else if(count!=0 && count!=rows-1){
                        this.jsonString="{success:true,message:'失败"+errorcount+"条记录,成功"+count+"条记录'}";
                        getRequest().setAttribute("jsonString", jsonString);
                        return SUCCESS;
                    }else if(count==0){
                        this.jsonString="{success:false,message:'操作失败,请联系管理员'}";
                        getRequest().setAttribute("jsonString", jsonString);
                        return SUCCESS;
                    }
                }
                rwb.close();
                File file=new File(rootPath+newFileName);
                if(file.exists()){
                    file.delete();
                }
                return SUCCESS;
            }
            this.jsonString="{success:false,message:'操作失败,请联系管理员'}";
            getRequest().setAttribute("jsonString", jsonString);
            return INPUT;
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return SUCCESS;
    }
    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }
    
    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }
    
    /**
     * @return the success
     */
    public boolean isSuccess() {
        return success;
    }
    
    /**
     * @param success the success to set
     */
    public void setSuccess(boolean success) {
        this.success = success;
    }
    
    /**
     * @return the page
     */
    public Page getPage() {
        return page;
    }
    
    /**
     * @param page the page to set
     */
    public void setPage(Page page) {
        this.page = page;
    }
    
    /**
     * @return the id
     */
    public Integer getId() {
        return id;
    }
    
    /**
     * @param id the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }
    
    /**
     * @return the userName
     */
    public String getUserName() {
        return userName;
    }
    
    /**
     * @param userName the userName to set
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }
    
    /**
     * @return the passWord
     */
    public String getPassWord() {
        return passWord;
    }
    
    /**
     * @param passWord the passWord to set
     */
    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }
    
    /**
     * @return the upload
     */
    public File getUpload() {
        return upload;
    }
    
    /**
     * @param upload the upload to set
     */
    public void setUpload(File upload) {
        this.upload = upload;
    }
    
    /**
     * @return the uploadFileName
     */
    public String getUploadFileName() {
        return uploadFileName;
    }
    
    /**
     * @param uploadFileName the uploadFileName to set
     */
    public void setUploadFileName(String uploadFileName) {
        this.uploadFileName = uploadFileName;
    }
    
    /**
     * @return the list
     */
    public List<?> getList() {
        return list;
    }
    
    /**
     * @param list the list to set
     */
    public void setList(List<?> list) {
        this.list = list;
    }
    

    }

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(16条)

报告相同问题?

悬赏问题

  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?