一個有關struts+spring+hibernate專案的問題,
我這幾天在用struts+spring+hibernate寫了一個專案。我的環境配置是eclipse3.2 jdk1.5 tomcat5.0.28 struts1.2.9 spring1.2.7 hibernate3.我在除錯的時候總是丟擲錯誤,以下是我的配置檔案
《application-Context.xml》
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>"com.managerFiler.dao.model.File.hbm.xml"</value>
<value>"com.managerFiler.dao.model.User.hbm.xml"</value>
</list>
</property>
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="fileDAO" class="com.managerFile.dao.Impl.FileDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userDAO" class="com.managerFile.dao.Impl.UserDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="**">PROPAGATION_REQUIRED</prop>
<prop key="**">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="**">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="fileDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="fileDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="**">PROPAGATION_REQUIRED</prop>
<prop key="**">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="**">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="fileService"
class="com.managerFile.service.impl.FileServiceImpl">
<property name="fileDAO">
<ref bean="fileDAO" />
</property>
</bean>
<bean id="userService"
class="com.managerFile.service.impl.UserServiceImpl">
<property name="userDAO">
<ref bean="userDAO" />
</property>
</bean>
<bean name="/loginAction" class="com.managerFile.action.LoginAction">
<property name="userService">
<ref bean="userService"/>
</property>
</bean>
<bean name="/indexAction" class="com.managerFile.action.IndexAction">
<!-- <property name="userService">
<ref bean="userService"/>
</property>
<property name="fileService">
<ref bean="fileService"/>
</property>-->
</bean>
<bean name="/registAction" class="com.managerFile.action.RegistAction">
<!-- <property name="userService">
<ref bean="userService"/>
</property>-->
</bean>
<bean name="/up_FileAction" class="com.managerFile.action.UpFileAction">
<!-- <property name="userService">
<ref bean="userService"/>
</property>
<property name="fileService">
<ref bean="fileService"/>
</property>-->
</bean>
<bean name="/fileManagerAction" class="com.managerFile.action.FileManagerAction">
<!-- <property name="fileService">
<ref bean="fileService"/>
</property>-->
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/mydb</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123-789</value>
</property>
</bean>
</beans>
<<web.xml>>
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app >
<display-name >ManagerFile</display-name>
<context-param >
<param-name >contextConfigLocation</param-name>
<param-value >/WEB-INF/application-Context.xml</param-value>
</context-param>
<!-- <listener >
<listener-class >org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> -->
<servlet>
<servlet-name>
context
</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet >
<servlet-name >action</servlet-name>
<servlet-class >org.apache.struts.action.Actionservlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping >
<servlet-name >action</servlet-name>
<url-pattern >*.do</url-pattern>
</servlet-mapping>
<welcome-file-list >
<welcome-file >welcome.jsp</welcome-file>
<welcome-file>/WEB-INF/pages/login.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri >/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location >/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri >/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location >/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri >/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location >/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
</web-app>
<<struts-config.xml>>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd" >
<struts-config>
<form-beans >
<form-bean name="LoginForm" type="com.managerFiler.form.LoginForm" />
<form-bean name="registForm" type="com.managerFiler.form.RegistForm" />
<form-bean name="upFileForm" type="com.managerFiler.form.UpFileForm" />
<form-bean name="managerFilerForm" type="com.managerFiler.form.ManagerFilerForm" />
</form-beans>
<global-forwards>
<forward name="welcome" path="loginAction.do" ></forward>
</global-forwards>
<action-mappings>
<action
input="/WEB-INF/pages/login.jsp"
name="LoginForm"
path="/loginAction"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="index" path="/WEB-INF/pages/index.jsp" />
<forward name="login" path="/WEB-INF/pages/login.jsp" />
</action>
<action
input="/WEB-INF/pages/regist.jsp"
name="registFrom"
path="/registAction"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="index" path="/WEB-INF/pages/index.jsp" />
<forward name="regist" path="/WEB-INF/pages/regist.jsp" />
</action>
<action
path="/indexAction"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false">
<forward name="index" path="/WEB-INF/pages/index.jsp" />
</action>
<action path="/fileManagerAction" type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="succeess" path="/WEB-INF/pages/success.jsp" />
<forward name="farilur" path="/WEB-INF/pages/farilur.jsp" />
</action>
<action
input="/WEB-INF/pages/up_File.jsp"
name="upFileForm"
path="/up_FileAction"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="farilur" path="/WEB-INF/pages/up_File.jsp" />
<forward name="success" path="/WEB-INF/pages/index.jsp" />
</action>
<action path="/fileManager" input="/WEB-INF/pages/fileManager.jsp" scope="request" type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="farilur" path="/WEB-INF/pages/fileManager.jsp"></forward>
<forward name="success" path="/WEB-INF/pages/index.jsp"></forward>
</action>
<action path="/regist" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/regist.jsp" scope="request"></action>
<action path="/up_File" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/up_File.jsp" scope="request"></action>
<action path="/down_File" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/down_File.jsp" scope="request"></action>
<action path="/fileManager" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/fileManager.jsp" scope="request"></action>
<action path="/logout" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/logout.jsp" scope="request"></action>
</action-mappings>
<!-- <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"> </controller>-->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/application-Context.xml"/>
</plug-in>
</struts-config>
package com.managerFile.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.managerFile.dao.model.User;
import com.managerFile.service.UserService;
import com.managerFile.web.form.LoginForm;
public class LoginAction extends BaseAction {
@SuppressWarnings("deprecation")
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
LoginForm lForm=(LoginForm) form;
String user_Name=lForm.getUser_Name();
String user_PassWord=lForm.getPassWord();
ActionErrors errors=new ActionErrors();
UserService userService=null;
try{
ApplicationContext ctx =
WebApplicationContextUtils.getWebApplicationContext(this.getServlet().getServletContext());
userService=(UserService) ctx.getBean("userService");
User user=userService.getUser(user_Name);
if(user.getUser_Name().equals(null)){
return mapping.findForward("login");
}
if(user.getUser_PassWord().equals(null)){
return mapping.findForward("login");
}
if(user.getUser_Name().equals(user_Name)||user.getUser_PassWord().equals(user_PassWord)){
return mapping.findForward("index");
}
else{
return mapping.findForward("login");
}
}
catch(Exception ex){
ex.printStackTrace();
errors.add("name", new ActionError("id"));
}
return null;
}
}
<<一個action>>yywrpackage com.managerFile.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.managerFile.dao.model.User;
import com.managerFile.service.UserService;
import com.managerFile.web.form.LoginForm;
public class LoginAction extends BaseAction {
@SuppressWarnings("deprecation")
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
LoginForm lForm=(LoginForm) form;
String user_Name=lForm.getUser_Name();
String user_PassWord=lForm.getPassWord();
ActionErrors errors=new ActionErrors();
UserService userService=null;
try{
ApplicationContext ctx =
WebApplicationContextUtils.getWebApplicationContext(this.getServlet().getServletContext());
userService=(UserService) ctx.getBean("userService");
User user=userService.getUser(user_Name);
if(user.getUser_Name().equals(null)){
return mapping.findForward("login");
}
if(user.getUser_PassWord().equals(null)){
return mapping.findForward("login");
}
if(user.getUser_Name().equals(user_Name)||user.getUser_PassWord().equals(user_PassWord)){
return mapping.findForward("index");
}
else{
return mapping.findForward("login");
}
}
catch(Exception ex){
ex.printStackTrace();
errors.add("name", new ActionError("id"));
}
return null;
}
}
請各位大俠幫助小弟看看是哪配置不對,每一次配置都說servlet action 不對。小弟在此謝謝大家了
<<一個jsp檔案>>
《application-Context.xml》
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>"com.managerFiler.dao.model.File.hbm.xml"</value>
<value>"com.managerFiler.dao.model.User.hbm.xml"</value>
</list>
</property>
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/pages/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="fileDAO" class="com.managerFile.dao.Impl.FileDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userDAO" class="com.managerFile.dao.Impl.UserDAOImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="userDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="**">PROPAGATION_REQUIRED</prop>
<prop key="**">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="**">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="fileDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="fileDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="**">PROPAGATION_REQUIRED</prop>
<prop key="**">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="**">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="fileService"
class="com.managerFile.service.impl.FileServiceImpl">
<property name="fileDAO">
<ref bean="fileDAO" />
</property>
</bean>
<bean id="userService"
class="com.managerFile.service.impl.UserServiceImpl">
<property name="userDAO">
<ref bean="userDAO" />
</property>
</bean>
<bean name="/loginAction" class="com.managerFile.action.LoginAction">
<property name="userService">
<ref bean="userService"/>
</property>
</bean>
<bean name="/indexAction" class="com.managerFile.action.IndexAction">
<!-- <property name="userService">
<ref bean="userService"/>
</property>
<property name="fileService">
<ref bean="fileService"/>
</property>-->
</bean>
<bean name="/registAction" class="com.managerFile.action.RegistAction">
<!-- <property name="userService">
<ref bean="userService"/>
</property>-->
</bean>
<bean name="/up_FileAction" class="com.managerFile.action.UpFileAction">
<!-- <property name="userService">
<ref bean="userService"/>
</property>
<property name="fileService">
<ref bean="fileService"/>
</property>-->
</bean>
<bean name="/fileManagerAction" class="com.managerFile.action.FileManagerAction">
<!-- <property name="fileService">
<ref bean="fileService"/>
</property>-->
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/mydb</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>123-789</value>
</property>
</bean>
</beans>
<<web.xml>>
<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app >
<display-name >ManagerFile</display-name>
<context-param >
<param-name >contextConfigLocation</param-name>
<param-value >/WEB-INF/application-Context.xml</param-value>
</context-param>
<!-- <listener >
<listener-class >org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> -->
<servlet>
<servlet-name>
context
</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet >
<servlet-name >action</servlet-name>
<servlet-class >org.apache.struts.action.Actionservlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping >
<servlet-name >action</servlet-name>
<url-pattern >*.do</url-pattern>
</servlet-mapping>
<welcome-file-list >
<welcome-file >welcome.jsp</welcome-file>
<welcome-file>/WEB-INF/pages/login.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri >/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location >/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri >/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location >/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri >/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location >/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
</web-app>
<<struts-config.xml>>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd" >
<struts-config>
<form-beans >
<form-bean name="LoginForm" type="com.managerFiler.form.LoginForm" />
<form-bean name="registForm" type="com.managerFiler.form.RegistForm" />
<form-bean name="upFileForm" type="com.managerFiler.form.UpFileForm" />
<form-bean name="managerFilerForm" type="com.managerFiler.form.ManagerFilerForm" />
</form-beans>
<global-forwards>
<forward name="welcome" path="loginAction.do" ></forward>
</global-forwards>
<action-mappings>
<action
input="/WEB-INF/pages/login.jsp"
name="LoginForm"
path="/loginAction"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="index" path="/WEB-INF/pages/index.jsp" />
<forward name="login" path="/WEB-INF/pages/login.jsp" />
</action>
<action
input="/WEB-INF/pages/regist.jsp"
name="registFrom"
path="/registAction"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="index" path="/WEB-INF/pages/index.jsp" />
<forward name="regist" path="/WEB-INF/pages/regist.jsp" />
</action>
<action
path="/indexAction"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false">
<forward name="index" path="/WEB-INF/pages/index.jsp" />
</action>
<action path="/fileManagerAction" type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="succeess" path="/WEB-INF/pages/success.jsp" />
<forward name="farilur" path="/WEB-INF/pages/farilur.jsp" />
</action>
<action
input="/WEB-INF/pages/up_File.jsp"
name="upFileForm"
path="/up_FileAction"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="farilur" path="/WEB-INF/pages/up_File.jsp" />
<forward name="success" path="/WEB-INF/pages/index.jsp" />
</action>
<action path="/fileManager" input="/WEB-INF/pages/fileManager.jsp" scope="request" type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="farilur" path="/WEB-INF/pages/fileManager.jsp"></forward>
<forward name="success" path="/WEB-INF/pages/index.jsp"></forward>
</action>
<action path="/regist" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/regist.jsp" scope="request"></action>
<action path="/up_File" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/up_File.jsp" scope="request"></action>
<action path="/down_File" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/down_File.jsp" scope="request"></action>
<action path="/fileManager" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/fileManager.jsp" scope="request"></action>
<action path="/logout" type="org.apache.struts.actions.ForwardAction" parameter="/WEB-INF/pages/logout.jsp" scope="request"></action>
</action-mappings>
<!-- <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"> </controller>-->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/application-Context.xml"/>
</plug-in>
</struts-config>
package com.managerFile.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.managerFile.dao.model.User;
import com.managerFile.service.UserService;
import com.managerFile.web.form.LoginForm;
public class LoginAction extends BaseAction {
@SuppressWarnings("deprecation")
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
LoginForm lForm=(LoginForm) form;
String user_Name=lForm.getUser_Name();
String user_PassWord=lForm.getPassWord();
ActionErrors errors=new ActionErrors();
UserService userService=null;
try{
ApplicationContext ctx =
WebApplicationContextUtils.getWebApplicationContext(this.getServlet().getServletContext());
userService=(UserService) ctx.getBean("userService");
User user=userService.getUser(user_Name);
if(user.getUser_Name().equals(null)){
return mapping.findForward("login");
}
if(user.getUser_PassWord().equals(null)){
return mapping.findForward("login");
}
if(user.getUser_Name().equals(user_Name)||user.getUser_PassWord().equals(user_PassWord)){
return mapping.findForward("index");
}
else{
return mapping.findForward("login");
}
}
catch(Exception ex){
ex.printStackTrace();
errors.add("name", new ActionError("id"));
}
return null;
}
}
<<一個action>>yywrpackage com.managerFile.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.managerFile.dao.model.User;
import com.managerFile.service.UserService;
import com.managerFile.web.form.LoginForm;
public class LoginAction extends BaseAction {
@SuppressWarnings("deprecation")
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
LoginForm lForm=(LoginForm) form;
String user_Name=lForm.getUser_Name();
String user_PassWord=lForm.getPassWord();
ActionErrors errors=new ActionErrors();
UserService userService=null;
try{
ApplicationContext ctx =
WebApplicationContextUtils.getWebApplicationContext(this.getServlet().getServletContext());
userService=(UserService) ctx.getBean("userService");
User user=userService.getUser(user_Name);
if(user.getUser_Name().equals(null)){
return mapping.findForward("login");
}
if(user.getUser_PassWord().equals(null)){
return mapping.findForward("login");
}
if(user.getUser_Name().equals(user_Name)||user.getUser_PassWord().equals(user_PassWord)){
return mapping.findForward("index");
}
else{
return mapping.findForward("login");
}
}
catch(Exception ex){
ex.printStackTrace();
errors.add("name", new ActionError("id"));
}
return null;
}
}
請各位大俠幫助小弟看看是哪配置不對,每一次配置都說servlet action 不對。小弟在此謝謝大家了
<<一個jsp檔案>>
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>無標題文件</title> </head> <body> <form name="LoginFrom" method="post" action="loginAction.do"> <p> </p> <label> <div align="center"> <pre> 使用者名稱 <input name="userName" type="text" align="middle" height="20"> 密 碼 <input name="userPassWord" type="password" height="20"> <input type="submit" name="Submit" value="登入"> <input type="reset" name="Submit2" value="重置"> <a href="regist.do">請先註冊</a> </pre> <div align="right"> <pre> </pre> </div> </div> </label> </form> </body> </html> <p class="indent"> |
相關文章
- 請問一個有關jdbc效能的問題JDBC
- 一個電商專案的Web服務化改造2:現有專案的5個問題Web
- 專案管理中的關鍵問題有哪些「上篇」專案管理
- 專案管理中的關鍵問題有哪些「下篇」專案管理
- 一個專案的一塊設計問題
- 有關*.properties檔案的問題
- create-react-app 建立專案有關less的若干問題ReactAPP
- create-react-app 建立專案有關 less 的若干問題ReactAPP
- 發現一個有關error的非常奇怪的問題Error
- 請教一個有關bibernate的session的問題Session
- 有關使用JAVA技術來操作ZIP檔案的一個問題,很急的!!!!!!Java
- 請教如何處理現有小專案的關聯關係的問題
- mozjpeg:Mozilla的一個有關影象壓縮的新專案
- 一個有關多域名session的問題,比較棘手Session
- JBOSS 做專案時的問題 有關Jboss, Mbean, Session bean 求助BeanSession
- 個人專案相關問題
- 問一個跟專案經驗不是很緊的問題~
- 記錄一個新專案遇到的 MySQL 問題MySql
- 常見的專案管理問題有哪些?專案管理
- 關於一個java專案呼叫另一個java專案的心得Java
- 有關 socialiteproviders 存在的幾個問題IDE
- [全程建模]一個專案UML設計中的幾個問題
- 關於教程的一個問題
- 關於lnmp配置laravel專案的問題?LNMPLaravel
- 關於專案內模組引用的問題
- 請教一個問題,關於上傳檔案和圖片的問題
- 問一個有關JBPM連MySQL資料庫的問題,高手請進MySql資料庫
- 有關專案的估算
- 各位十一好,問一個有關weblogic 8的連線池的問題Web
- jdon 你好!有個概念上的問題請教!專案中要用...
- 請問在JAVA WEB專案中一個比較棘手的問題JavaWeb
- 有關C++引數傳值的一個問題探討C++
- 記新專案中遇到的有關農曆,日曆元件的所有問題。元件
- 關於一個公益專案的探究
- 請教您關於 Nginx 下多個 Laravel 專案的部署問題NginxLaravel
- 有關模型關聯的問題模型
- 關於網站專案報價的問題網站
- 關於idea部署本地專案的問題Idea