JAVA中这种写法合理吗?

言月秋 2015-04-14 09:31:20
LogingServiceAction 中
public String execute() throws Exception{
List<User> userList=userdao.findByName(username);
for(User user:userList){
if(user.getPassword().equals(password)){
return SUCCESS;
}
else{
return ERROR;
}
}
return ERROR;
}
}
在某个地方看见上面这代码,其中 ,如return SUCCESS,这种代码可以这么写吗,存在的依据又是什么?
...全文
152 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
言月秋 2015-04-14
  • 打赏
  • 举报
回复
引用 4 楼 Molly_1994 的回复:
引用 2 楼 yanyueqiu 的回复:
[quote=引用 1 楼 Molly_1994 的回复:] 啥意思啊,这代码有什么问题吗
简单说就是在eclipse中这么写报错
它这个类不是单独存在的,struts里需要继承某个Action,SUCCESS那些都是定义过的常量[/quote] 看了另一位仁兄给的答案,明白了。
gzqGyula 2015-04-14
  • 打赏
  • 举报
回复
liucatch 说的不错,你也可以直接用 return “success” 就是为了给前台返回一个处理结果
anakin_feng 2015-04-14
  • 打赏
  • 举报
回复
引用 2 楼 yanyueqiu 的回复:
引用 1 楼 Molly_1994 的回复:
啥意思啊,这代码有什么问题吗
简单说就是在eclipse中这么写报错
它这个类不是单独存在的,struts里需要继承某个Action,SUCCESS那些都是定义过的常量
liucatch 2015-04-14
  • 打赏
  • 举报
回复
可以这么写,基类里面是有定义的。 public interface Action { /** * The action execution was successful. Show result * view to the end user. */ public static final String SUCCESS = "success"; /** * The action execution was successful but do not * show a view. This is useful for actions that are * handling the view in another fashion like redirect. */ public static final String NONE = "none"; /** * The action execution was a failure. * Show an error view, possibly asking the * user to retry entering data. */ public static final String ERROR = "error"; /** * The action execution require more input * in order to succeed. * This result is typically used if a form * handling action has been executed so as * to provide defaults for a form. The * form associated with the handler should be * shown to the end user. * <p/> * This result is also used if the given input * params are invalid, meaning the user * should try providing input again. */ public static final String INPUT = "input"; /** * The action could not execute, since the * user most was not logged in. The login view * should be shown. */ public static final String LOGIN = "login"; /** * Where the logic of the action is executed. * * @return a string representing the logical result of the execution. * See constants in this interface for a list of standard result values. * @throws Exception thrown if a system level exception occurs. * <b>Note:</b> Application level exceptions should be handled by returning * an error value, such as <code>Action.ERROR</code>. */ public String execute() throws Exception; }
言月秋 2015-04-14
  • 打赏
  • 举报
回复
引用 1 楼 Molly_1994 的回复:
啥意思啊,这代码有什么问题吗
简单说就是在eclipse中这么写报错
anakin_feng 2015-04-14
  • 打赏
  • 举报
回复
啥意思啊,这代码有什么问题吗

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧