servlet+spring myEclipse
servlet类中:
}
service中:
/**
* 注册
*@param LoginPass
*@return 1:注册成功 2.已注册 0.系统异常
*/
public int regist(String username){
int flag=0;
try {
Connection conn = ConnectionUtil.getConn();
String sql = "select username from users where username = '"+ username +"'";
PreparedStatement psmt = conn.prepareStatement(sql);
ResultSet rs = psmt.executeQuery(sql);
String tempName="";
while(rs.next()){
tempName=rs.getString("username");
}
//如果没有值,保存用户,并提示注册成功
if(tempName.isEmpty()){
saveEntity(user);
flag=1;
}else{
flag=2;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return flag;
}
private void saveEntity(User user) {
try {
Connection conn = ConnectionUtil.getConn();
String sql = "insert into users (username,password,comfirmpwd,phone,email)"
+"values('"+user.getUserName()+","+user.getPassword()+","
+user.getConfirmPwd()+","+user.getPhone()+","+user.getEmail()+"')";
PreparedStatement psmt = conn.prepareStatement(sql);
int count = psmt.executeUpdate(sql);
System.out.println("保存了"+count+"条用户信息");
} catch (SQLException e) {
e.printStackTrace();
}
}
web.xml中:
<servlet>
<servlet-name>RegistAction</servlet-name>
<servlet-class>com.xue.manager.ServletToBeanProxy</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistAction</servlet-name>
<url-pattern>/RegistAction</url-pattern>
</servlet-mapping>
beans.xml中:
<bean id="RegistAction" class="com.xue.action.RegistAction"/>
配置了数据源,但是运行不报错,点击页面注册功能,只出现打印信息“This is class com.xue.action.RegistAction, using the POST method” 没有走写的代码程序?怎么回事呢?
怪异的用法,你的 <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">ServletToBeanProxy是怎么样的。<divclass="ref">
去掉这两个注解:
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14.399999618530273px;line-height:22px;background-color:#FFFFFF;">@Controller
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14.399999618530273px;line-height:22px;background-color:#FFFFFF;">@Scope("prototype")
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。