首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

整合SSH框架,出现 Servlet action is not available,该如何处理

2012-01-19 
整合SSH框架,出现 Servlet action is not availableweb.xml的配置文件如下:servletservlet-nameaction

整合SSH框架,出现 Servlet action is not available
web.xml的配置文件如下:

  <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>
  <init-param>
  <param-name>debug</param-name>
  <param-value>3</param-value>
  </init-param>
  <init-param>
  <param-name>detail</param-name>
  <param-value>3</param-value>
  </init-param>
  <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.do</url-pattern>
  </servlet-mapping>

struts-config.xml的配置文件:

<struts-config>
  <data-sources />
  <form-beans >
  <form-bean name="userForm" type="struts.form.UserForm" />

  </form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings >
  <action
  attribute="userForm"
  input="/JSP/user.jsp"
  name="userForm"
  path="/user"
  scope="request"
  type="struts.action.UserAction">
  <forward name="success" path="/JSP/Success.jsp" />
  <forward name="failure" path="/JSP/user.jsp" />
  </action>

  </action-mappings>
  <plug-in
  className="org.springframework.web.struts.ContextLoaderPlugIn">
  <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
  </plug-in>
  <controller
  processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />
  <message-resources parameter="struts.ApplicationResources" />
</struts-config>

Spring中applicationContext.xml的配置如下:<beans>


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>file:WebRoot/WEB-INF/hibernate.cfg.xml</value>
</property>
</bean>
<bean id="UseraDAO" class="HibernateSession.UseraDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean name="/user" class="struts.action.UserAction">
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>


<bean id="userDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref local="transactionManager" />
</property>
<property name="target">
<ref local="UseraDAO" />


</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>

Hibernate的配置文件如下:

<hibernate-configuration>

<session-factory>
<property name="connection.username">ruanwxh</property>
<property name="connection.url">
jdbc:microsoft:sqlserver://localhost:1433
</property>
<property name="dialect">
org.hibernate.dialect.SQLServerDialect
</property>
<property name="myeclipse.connection.profile">SQL</property>
<property name="connection.password">ruan0953</property>
<property name="connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<mapping resource="HibernateSession/Usera.hbm.xml" />

</session-factory>

</hibernate-configuration>

映射文件:<hibernate-mapping>
  <class name="HibernateSession.Usera" table="usera" schema="dbo" catalog="Test">
  <id name="id" type="java.lang.Integer">
  <column name="id" />
  <generator class="increment" />
  </id>
  <property name="name" type="java.lang.String">
  <column name="username" length="50" />
  </property>
  <property name="password" type="java.lang.String">
  <column name="userpassword" length="50" />
  </property>
  <property name="age" type="java.lang.Integer">
  <column name="age" />
  </property>
  </class>
</hibernate-mapping>

JSP的Action如下:
  <html:form action="/user">
username : <html:text property="name"/><br/>
password : <html:password property="password"/><br/>
  <html:submit value="提交"/><html:cancel value="取消"/>
  </html:form>

[解决办法]
应该是路径问题

不能识别Action
[解决办法]
你既然用了Spring插件了,自然就是Spring去管理你的action

<action-mappings >
<action
attribute="userForm"
input="/JSP/user.jsp"
name="userForm"
path="/user"
scope="request"
type="struts.action.UserAction">
<forward name="success" path="/JSP/Success.jsp" />
<forward name="failure" path="/JSP/user.jsp" />
</action> 

上面我标红的地方如果不用Spring。你可以直接写全名对应上,但你现在用到Spring了,struts.action.UserAction这个地方就应该是Spring中的一个bean id 了。你在applicationContext.xml中定义一个就行了(出错是因为你没定义)
[解决办法]
<action-mappings > 
<action 
attribute="userForm" 
input="/JSP/user.jsp" 
name="userForm" 
path="/user" 
scope="request" 

<forward name="success" path="/JSP/Success.jsp" /> 


<forward name="failure" path="/JSP/user.jsp" /> 
</action>
[解决办法]
是struts-config.xml的配置文件错了: 

<action-mappings > 
<action 
attribute="userForm" 
input="/JSP/user.jsp" 
name="userForm" 
path="/user" 
scope="request" 
type="struts.action.UserAction">//这里错了 
<forward name="success" path="/JSP/Success.jsp" /> 
<forward name="failure" path="/JSP/user.jsp" /> 
</action> 
改成:
type="org.springframework.web.struts.DelegatingActionProxy"

[解决办法]
在web.xml里加入对spring的监听

热点排行