Struts2基于注解配置Action
来源:互联网 发布:喵社交软件 编辑:程序博客网 时间:2024/05/17 01:05
期末的一个作业老师要求用注解完成,那么先简单的写一个基于注解的Action配置。
LoginAction部分代码:
@Action(value="loginUI",results={
@Result(name="loginUI",location="/index.jsp")
})
//跳转到登录页面
public String loginUI (){
return "loginUI";
}
@Action(value = "employee_login", results = { @Result(name="login", type = "redirect" ,
location="frist.action")})
//真正处理登录
public String login() throws Exception{
//System.out.println(model.getAccount()+model.getPassword());
Employee employee = employeeService.getById(model);
//System.out.println(employee);
// 获得response对象,项页面输出:
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
if(employee==null){
response.getWriter().println("<font color='red'>没有该员工号!</font>");
return "loginUI";
}
if (model.getPassword()==employee.getPassword()) {
// 登录失败
//addFieldError("employee", "用户名或密码不正确!");
response.getWriter().println("<font color='red'>密码不正确!</font>");
return "loginUI";
} else {
// 登录成功
ActionContext.getContext().getSession().put("employee", employee);
//ServletActionContext.getRequest().getSession().setAttribute("employee", employee);
return "login";
}
}
下面是login.jsp主要代码:
<form action="${pageContext.request.contextPath}/login.action"
method="post">
<input type="text" name="id" id="id" value="ACCOUNT"
onfocus="this.value = '';"
onblur="if (this.value == '') {this.value = 'USERNAME';}">
<input
type="password" id="password" name="password" value="PASSWORD"
onfocus="this.value = '';"
onblur="if (this.value == '') {this.value = 'PASSWORD';}">
<input
type="submit" name="submit" value="SIGN IN">
</form>
这样就完成啦!当然struts.xml不能有action标签要加上一些内容
<constant name="struts.devMode" value="false" />
<!-- struts2的国际化大致上分为页面的国际化,Action的国际化以及xml的国际化-->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 是否使用struts的开发模式。开发模式会有更多的调试信息。默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.devMode" value="true" />
<!-- 指定被struts2处理的请求后缀类型。多个用逗号隔开 -->
<constant name="struts.action.extension" value="action,do"/>
<!-- 当struts.xml改动后,是否重新加载。默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- 设置浏览器是否缓存静态内容。默认值为true(生产环境下使用),开发阶段最好关闭 -->
<constant name="struts.serve.static.browserCache" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
- Struts2基于注解配置action
- Struts2基于注解配置Action
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置(一)
- Struts2基于注解的Action配置(二)
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- Struts2基于注解的Action配置
- "內存碎片"疑似“内存泄漏”
- 为什么要使用SLF4J而不是Log4J
- 你和月薪6位数的人,差距究竟在哪里?「用户案例」
- log4j 滚动日志 及 实现操作日志
- 浅谈javascript对象、如何实现继承、jQuery方法的扩展(jquery插件)
- Struts2基于注解配置Action
- input number maxlength 失效 移动端使用
- android学习笔记6.07
- 第三方框架 开源项目
- thinkphp 常量的定义
- stringByReplacingOccurrencesOfString 去掉字符串,替换空格等等
- iOS 中使用JS提取网页数据,自动提交表单等
- 标准自定义控件CirvleView
- easyui之form表单提交