Spring+Struts时遇到问题了

悬赏:3 发布时间:2008-07-16 提问人:wangbaoping (初级程序员)

我在struts-config.xml中这样配置
<struts-config>
<data-sources />
<form-beans>
<form-bean name="userInfoForm" type="com.soho.webtier.struts.form.UserInfoForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action name="userInfoForm" path="/login" parameter="method" scope="request" type="com.soho.webtier.struts.action.LoginAction" validate="false">
<forward name="ok" path="ok.jsp" redirect="true" />
</action>
</action-mappings>
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>
<message-resources parameter="com.soho.webtier.struts.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml"/>
</plug-in>
</struts-config>
在applicationContext.xml中这样配置
<bean id="UserinfoService" class="com.soho.service.UserinfoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="/login" class="com.soho.webtier.struts.action.LoginAction">
<property name="UserinfoService">
<ref local="UserinfoService" />
</property>
</bean>
这是ACTION
public class LoginAction extends DispatchAction {
public UserinfoService UserinfoService;

public UserinfoService getUserinfoService() {
return UserinfoService;
}

public void setUserinfoService(UserinfoService userinfoService) {
UserinfoService = userinfoService;
}

public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserInfoForm loginForm = (UserInfoForm) form;// TODO Auto-generated
// // method stub
// 获得 WebApplicationContext 对象
/*
* WebApplicationContext ctx = this.getWebApplicationContext();
* UserinfoService dao = (UserinfoService)
* ctx.getBean("UserinfoService");
*/
Userinfo user = new Userinfo();
user.setUserName(request.getParameter("userName"));
user.setPassword(request.getParameter("password"));
UserinfoService.saveUser(user);
UserinfoService.insert(user);
return mapping.findForward("ok");
}
但是在运行时竟然出说ACTION不可求,是找不到STRUTS的ACTION。

采纳的答案

2008-07-16 lggege (资深程序员)

<bean id="UserinfoService" class="com.soho.service.UserinfoDAO"> 
<property name="sessionFactory"> 
<ref bean="sessionFactory" /> 
</property> 
</bean> 


public class LoginAction extends DispatchAction { 
public UserinfoService UserinfoService; 
// 这里将一个UserinfoDAO注成UserinfoService 肯定会出错的


既然Web启动就没有成功,在进行访问的时候,也就会提示请求不可用.


看这两段代码,是否应该将配置修改成:
<bean id="UserinfoDAO" class="com.soho.service.UserinfoDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="UserinfoService" class="com.soho.service.UserinfoService">
<property name="UserinfoDAO">
<ref bean="UserinfoDAO" />
</property>
</bean>

提问者对于答案的评价:
very good