Help: SSH + jquery + json to do a simple login example, getHibernateTemplate (). Find abnormal

Category: Web Develop
 
zblfff
2013-08-20 05:30:03

Sponsored Links
Learn SSH jquery json do a simple login process, as follows:

table
user: id name password grade
model
; User: id name password grade
User.hbm.xml:
/ / skip

UserDaoImpl:
; public User getUserByID (int id) {
return (User) this.getHibernateTemplate (). get (User.class, id);
}
; public User getUserByNameAndPass (String name, String pass) {
String sql = "from User u where u.name =? and u.password = ? ";
System.out.println (name +": "+ pass);
List userList = this.getHibernateTemplate (). find (sql, new Object [] {name, pass});
System.out.println (userList.size ());
return userList.size () == 0? null: (User) userList.get (0);
}
/ / other methods omitted

UserServiceImpl:
public User getUserByID (int id) {
return userDAO.getUserByID (id);
}
; public User getUserByNameAndPass (String name, String pass) {
return userDAO.getUserByNameAndPass (name, pass);
}

UserAction:
UserService userService;
private String username;
private String password;
private String grade;
private int result; / / 0 indicates Login failed, 1 indicates successful landing
public String login () throws Exception {
User user = userService.getUserByNameAndPass (username, password);
if (null == user) {
this.setResult (0);
} else {
this.setUsername (user.getName ());
this.setPassword ( user.getPassword ());
this.setGrade (user.getGrade ());
this.setResult (1);
}
return SUCCESS;
}

login.jsp:
function userLoginExe () {
var $ username = $ ('# username');
var $ password = $ ('# password');
if ($ username.val () =='') {
msgShow ( 'prompted', 'Please enter your user name!', 'warning');
return false;
}
if ($ password.val () =='') {
msgShow ('prompted', 'Please enter your password!', 'warning');
return false;
}
$. ajax ({
url: 'user / loginAction.action',
type: 'post' ,
data: {username: $ username.val (), password: $ password.val ()},
; dataType: 'json',
success: function (data) {
if (data.result == 0) {window.alert (" login failed! ")}
else if (data.result == 1) {window.alert (data.grade);}
}
});
}
/ / Other slightly

struts.xml:
<package name = "project" namespace = "/ user" extends = "json-default">
<action name = "loginAction" class = "cn.frh.action . UserAction "method =" login ">
<result name="success" type="json">
<param name =" includeProperties " ;>
result, username, password, grade
</param>
</result>
</action>
</package>

my user table to add a name = 'a' password = 'b' grade = "admin" record;
Logically I will be prompted to enter the press after landing landing landing fails or the user's grade (grade); however, do not pop up alert, no reported abnormal;
for testing, I'll loginAction the login of getUserByNameAndPass (name, password) with getUserByID (1) to test the results successfully alert ('admin'), instructions to configure all right;
So I set a breakpoint in UserDaoImpl's List userList = this.getHibernateTemplate (). find (sql, new Object [] {name, pass}) on this one, single-step debugging, pop exception:

Daemon Thread [ajp-8009-CometPoller-7] ; (Running)
Daemon Thread [http-8888-1] (Suspended)
DefaultActionInvocation.invokeAction (Object, ActionConfig) line: 468
DefaultActionInvocation . invokeActionOnly () line: 291
DefaultActionInvocation.invoke () line: 254
DefaultWorkflowInterceptor.doIntercept (ActionInvocation) line: 176
DefaultWorkflowInterceptor ( MethodFilterInterceptor). intercept (ActionInvocation) line: 98
DefaultActionInvocation.invoke () line: 248
AnnotationValidationInterceptor (ValidationInterceptor). doIntercept (ActionInvocation) line: 263
AnnotationValidationInterceptor.doIntercept (ActionInvocation) line: 68
AnnotationValidationInterceptor (MethodFilterInterceptor). intercept (ActionInvocation) line: 98
DefaultActionInvocation.invoke () line: 248
StrutsConversionErrorInterceptor (ConversionErrorInterceptor). intercept (ActionInvocation) line: 138
DefaultActionInvocation.invoke () line: 248
ParametersInterceptor.doIntercept (ActionInvocation) ; line: 207
ParametersInterceptor (MethodFilterInterceptor). intercept (ActionInvocation) line: 98
DefaultActionInvocation.invoke () line: 248
ActionMappingParametersInteceptor (ParametersInterceptor) . doIntercept (ActionInvocation) line: 207
ActionMappingParametersInteceptor (MethodFilterInterceptor). intercept (ActionInvocation) line: 98
DefaultActionInvocation.invoke () line: 248
StaticParametersInterceptor.intercept (ActionInvocation) line: 190
DefaultActionInvocation.invoke () line: 248
MultiselectInterceptor.intercept (ActionInvocation) line: 75
DefaultActionInvocation.invoke () line: 248
CheckboxInterceptor.intercept (ActionInvocation) line: 94
DefaultActionInvocation.invoke () line: 248
FileUploadInterceptor.intercept (ActionInvocation) line: 243
DefaultActionInvocation.invoke () line: 248
ModelDrivenInterceptor.intercept (ActionInvocation) line: 100
DefaultActionInvocation.invoke () line: 248
ScopedModelDrivenInterceptor.intercept (ActionInvocation) line: 141
DefaultActionInvocation.invoke () line: 248
DebuggingInterceptor.intercept (ActionInvocation) line: 270
DefaultActionInvocation.invoke () line: 248
ChainingInterceptor.intercept (ActionInvocation) line: 145
DefaultActionInvocation.invoke () line: 248
PrepareInterceptor.doIntercept (ActionInvocation) line: 171
PrepareInterceptor (MethodFilterInterceptor). intercept (ActionInvocation) line: 98
DefaultActionInvocation.invoke () line: 248
I18nInterceptor.intercept (ActionInvocation) line: 176
DefaultActionInvocation.invoke () line: 248
ServletConfigInterceptor.intercept (ActionInvocation) line: 164
DefaultActionInvocation.invoke () line: 248
AliasInterceptor.intercept (ActionInvocation) line: 190
DefaultActionInvocation.invoke () line: 248
ExceptionMappingInterceptor.intercept (ActionInvocation) line: 187
DefaultActionInvocation.invoke () line: 248
StrutsActionProxy.execute () line: 52
Dispatcher.serviceAction (HttpServletRequest, HttpServletResponse, ServletContext, ActionMapping) line: 498
FilterDispatcher.doFilter ( ServletRequest, ServletResponse, FilterChain) line: 434
ApplicationFilterChain.internalDoFilter (ServletRequest, ServletResponse) line: 235
ApplicationFilterChain.doFilter (ServletRequest, ServletResponse) line: 206
StandardWrapperValve.invoke (Request, Response) line: 233
StandardContextValve.invoke (Request, Response) line: 191
StandardHostValve.invoke (Request, Response) line: 127
ErrorReportValve.invoke (Request, Response) line: 102
StandardEngineValve.invoke (Request, Response) line: 109
CoyoteAdapter.service (Request, Response) line: 298
Http11AprProcessor.process (long) line: ; 864
Http11AprProtocol $ Http11ConnectionHandler.process (long) line: 579
AprEndpoint $ Worker.run () line: 1665
Thread.run () line: 619
execute the interrupt. .

seems wrong to find in hibernatetemplate methods?

sorts of unsuccessful searching, hope master guiding January

Sponsored Links

lzm121121
2013-08-20 05:36:32
this method public User getUserByNameAndPass (String name, String pass)
change for the following test under
final String sql = "from User u where u.name = '" + name + "' and u.password = ' "+ pass +" '";
List <User> userList = (List <User>) hibernateTemplate.execute (new HibernateCallback () {

@ Override
public Object doInHibernate (Session session)
throws HibernateException, SQLException {
return session.createQuery (sql). uniqueResult ();
}});
}
chenxi1020
2013-08-20 05:48:14
No, the same mistake! ~

willtong520
2013-08-20 06:05:54
run to the breakpoint of the variable information:

this UserDAOImpl (id = 104)
hibernateTemplate HibernateTemplate ; (id = 157)
logger Log4JLogger (id = 176)
name "a" (id = 145)
pass "b" ( id = 150)
sql "from User u where u.name =? and u.password =?" (id = 151)
count 43
hash 0
offset 0
value (id = 155)
ht HibernateTemplate (id = 157)
allowCreate true
alwaysUseNewSession false
beanFactory null
cacheQueries false
checkWriteOperations true
defaultJdbcExceptionTranslator null
entityInterceptor null
exposeNativeSession false
fetchSize 0
filterNames null
flushMode 1
jdbcExceptionTranslator null
logger Log4JLogger (id = 162)
maxResults 0
queryCacheRegion null
sessionFactory $ Proxy0 (id = 165)
h AbstractSessionFactoryBean $ TransactionAwareInvocationHandler (id = 172)
syjgod
2013-08-20 06:10:10
struts1.x not good for many years. . .
jail
2013-08-20 06:25:34
this is my struts2.X, official website of the new

Domain and server ip had changed since 8/23/2013. Suspend the user registration and posts for program maintenance.