Jsp页面是这样写的:
<center>
<s:form action="login" method="post">
<s:textfield name="empinfo.name" label="用户名" />
<s:password name="empinfo.password" label="密码" />
<s:submit value="登录" />
</s:form>
</center>
loginAction是这样写的:
public String userLogin() throws Exception { boolean bl = userLoginService.userLogin(empinfo);
if (bl) {
ActionContext act = ActionContext.getContext();
HttpServletRequest req = (HttpServletRequest) act
.get(ServletActionContext.HTTP_RESPONSE);
HttpSession session = req.getSession();// 获取当前会话对象的引用
session.setAttribute("user", empinfo);
return SUCCESS;
} return INPUT; }
Struts.xml里是这样配置的:
<struts>
<constant name="struts.custom.i18n.resources"
value="messageResource" />
<constant name="struts.i18n.encoding" value="GBK"></constant> <constant name="struts.objectFactory" value="spring" />
<include file="struts-default.xml" /> <package name="struts2" extends="struts-default">
<action name="login" class="userLogin" method="userLogin">
<result name="input">/jsp/login.jsp</result>
<result name="success">/jsp/index.jsp</result>
</action>
</package>
</struts>
Dao是这样实现的:
public class EmpinfoDaoImp extends BaseDao implements EmpinfoDao { public boolean userLogin(Empinfo empinfo) throws Exception {
try {
// 需要继承于类BaseDao
Session session = getSession();
Transaction tra = session.beginTransaction();
// Object[] args={empinfo.getName(),empinfo.getPassword()};
String hql = " from Empinfo e where e.name=? and e.password=? ";
Query query = (Query) session.createQuery(hql);
query.setParameter(0, empinfo.getName());
query.setParameter(1, empinfo.getPassword());
if (query.list().size() <= 0) {
tra.rollback();
session.close();
return false;
} else {
tra.commit();
session.close();
return true;
} } catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
dao_context.xml是这样配置的:
<bean id="userLogin" class="com.ribert.action.UserLoginAction">
<property name="empinfo">
<bean class="com.ribert.domain.Empinfo"></bean>
</property>
<property name="userLoginService" ref="loginService"></property>
</bean>
问题是我找不出类型转换错误在哪里。是不是我的配置上有问题。请高手帮忙,谢谢了。
<center>
<s:form action="login" method="post">
<s:textfield name="empinfo.name" label="用户名" />
<s:password name="empinfo.password" label="密码" />
<s:submit value="登录" />
</s:form>
</center>
loginAction是这样写的:
public String userLogin() throws Exception { boolean bl = userLoginService.userLogin(empinfo);
if (bl) {
ActionContext act = ActionContext.getContext();
HttpServletRequest req = (HttpServletRequest) act
.get(ServletActionContext.HTTP_RESPONSE);
HttpSession session = req.getSession();// 获取当前会话对象的引用
session.setAttribute("user", empinfo);
return SUCCESS;
} return INPUT; }
Struts.xml里是这样配置的:
<struts>
<constant name="struts.custom.i18n.resources"
value="messageResource" />
<constant name="struts.i18n.encoding" value="GBK"></constant> <constant name="struts.objectFactory" value="spring" />
<include file="struts-default.xml" /> <package name="struts2" extends="struts-default">
<action name="login" class="userLogin" method="userLogin">
<result name="input">/jsp/login.jsp</result>
<result name="success">/jsp/index.jsp</result>
</action>
</package>
</struts>
Dao是这样实现的:
public class EmpinfoDaoImp extends BaseDao implements EmpinfoDao { public boolean userLogin(Empinfo empinfo) throws Exception {
try {
// 需要继承于类BaseDao
Session session = getSession();
Transaction tra = session.beginTransaction();
// Object[] args={empinfo.getName(),empinfo.getPassword()};
String hql = " from Empinfo e where e.name=? and e.password=? ";
Query query = (Query) session.createQuery(hql);
query.setParameter(0, empinfo.getName());
query.setParameter(1, empinfo.getPassword());
if (query.list().size() <= 0) {
tra.rollback();
session.close();
return false;
} else {
tra.commit();
session.close();
return true;
} } catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
dao_context.xml是这样配置的:
<bean id="userLogin" class="com.ribert.action.UserLoginAction">
<property name="empinfo">
<bean class="com.ribert.domain.Empinfo"></bean>
</property>
<property name="userLoginService" ref="loginService"></property>
</bean>
问题是我找不出类型转换错误在哪里。是不是我的配置上有问题。请高手帮忙,谢谢了。
解决方案 »
- 高手请进:关于spring security access-denied-page被struts2拦截的问题
- struts action获取页面参数
- 怎样将别人的网站变成自己的
- java技术交流群87540701
- hibernate中简单的用Criteria实现多表查询问题
- 求个以字母开头,后面不能接任意数字的正则表达式?
- javamail版本问题(急)
- 讨论:MVC框架性能哪个较好?
- struts-config.xml里面图形界面怎么让它自动排版哦
- 在JBoss下部署ejb时,报错java.rmi.server.ExportException: Port already in use: 1098; nested exception is: 具体如下:
- 在tomcat项目中建立文件夹的问题
- JFreeChart 1.0.9问题
严重: Servlet.service() for servlet default threw exception
java.lang.ClassCastException: org.apache.catalina.connector.ResponseFacade cannot be cast to javax.servlet.http.HttpServletRequest
at com.ribert.action.UserLoginAction.userLogin(UserLoginAction.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
.get(ServletActionContext.HTTP_RESPONSE); 写程序要仔细你要的是REQUEST,但你GET的是RESPONSE