Struts2 Action无法获取获取表单数据错误及解决方法
来源:互联网 发布:网络灰色产业有哪些 编辑:程序博客网 时间:2024/04/30 17:01
LoginAction.java
package org.easybooks.bookstore.action;import java.sql.*;import org.easybooks.bookstore.jdbc.MySQLConnBean;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{private String username;private String password;public void setUserName(String username){this.username=username;}public String getUserName(){return username;}public void setPassword(String password){this.password=password;}public String getPassword(){return password;}public String execute() throws Exception{String usr=getUsername();String pwd=getPassword();boolean validated=false;MySQLConnBean MySqlBean=new MySQLConnBean();String sql="select * from user";MySqlBean.openConn();ResultSet rs=MySqlBean.executeQuery(sql);while(rs.next()){if(rs.getString("username").equals(usr) && (rs.getString("password").compareTo(pwd)==0)){validated=true;}}rs.close();MySqlBean.closeStmt();MySqlBean.closeConn();if(validated){ActionContext.getContext().getSession().put("user",getUsername());return SUCCESS;}else{return ERROR;}}}
<%@ page language="java" contentType="text/html; charset=UTF-8"%><html><head><title><s:text name="loginPage"/></title></head><body><form action="login"> NAME:<input type="text" name="username"/><br/> PASS:<input type="text" name="password"/><br/> <input type="submit" value="登录"/></form></body></html>
测试过程中发现在LoginAction中只能够获得password,不能够获得username
发生错误的原因是函数名大小写出错,把getUsername写成了getUserName
由此可见此类函数的命名应该特别小心.
0 0
- Struts2 Action无法获取获取表单数据错误及解决方法
- struts2 Action获取表单数据
- struts2 Action获取表单数据
- struts2 Action获取表单数据
- struts2 Action获取表单数据
- struts2 Action获取表单数据
- Struts2 Action类无法获取web表单数据
- (转)struts2 Action获取表单数据
- Struts2笔记04 action获取表单数据
- Struts2框架中action无法获取到jsp页面传递的表单数据的解决办法
- Struts2获取表单数据
- Action获取表单提交数据
- struts2 表单数据无法获取即显示为null
- history.go(-1)无法获取表单数据的解决方法
- struts2 Action获取表单传值
- struts2 Action获取表单内容总结
- struts2 无法获取action属性的问题解决
- 在Action中获取表单数据
- Vim基本使用
- windows管道系统 ----命名管道
- 华为机试(二)
- Fedora19升级20 步骤&问题记录
- Gmail上不去怎么办?
- Struts2 Action无法获取获取表单数据错误及解决方法
- ZOJ-1808
- hdu4336(状压dp求期望)
- PAT6-07. 哈利·波特的考试
- 谈写脚本、写代码和编程三者的区别
- HBase 在淘宝的应用和优化
- linux的系统调用
- Java语言基础
- js本身实现的弹出框