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

struts+hibernate+spring有关问题,说找不到action,n天没有解决了,呀!

2012-01-29 
struts+hibernate+spring问题,说找不到action,n天没有解决了,高手救命呀!!小弟我是第一次用strust+hiberna

struts+hibernate+spring问题,说找不到action,n天没有解决了,高手救命呀!!
小弟我是第一次用strust+hibernat+spring按照网上的一个例子说是找不到action.好多天没有解决,高手帮忙呀。下面我把部分代码贴上来,高手看看。。顺便问一下,web.xml里面用不用配spring的什么东东呀。。。

applicatContext.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= "configLocation ">
<value> classpath:hibernate.cfg.xml </value>
</property>
</bean>
<bean   id= "UserListDAO "   class= "com.jyx.UserListDAO ">
<property   name= "sessionFactory ">
<ref   bean= "sessionFactory "   />
</property>
</bean>
<bean   name= "/user "
        class= "com.jyz.user.action.UserAction ">
        <property   name= "userListDAO ">
            <ref   bean= "UserListDAO "/>
        </property>    
</bean>
</beans>

struts-config.xml

<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<!DOCTYPE   struts-config   PUBLIC   "-//Apache   Software   Foundation//DTD   Struts   Configuration   1.1//EN "   "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd ">
             
<struts-config>
    <data-sources   />
    <form-beans   />
    <global-exceptions   />
    <global-forwards   />
    <action-mappings   >
     
          <action       path             =   "/user "
                              type             =   "org.springframework.web.struts.DelegatingActionProxy "
                              validate     =   "false "
                              parameter   =   "method "                      
                                                             
        >
        <forward   name= "success "   path= "/success.jsp "/>
        </action>
 
    </action-mappings>

    <message-resources   parameter= "com.jyx.struts.ApplicationResources "   />
   
    <plug-in
      className= "org.springframework.web.struts.ContextLoaderPlugIn ">


      <set-property   property= "contextConfigLocation "  
                value= "/WEB-INT/applicationContext.xml "/>
  </plug-in>  
</struts-config>

UserAction   ::

  package   com.jyz.user.action;
import   org.hibernate.*;
import   org.hibernate.Session;
import   org.hibernate.cfg.*;
import   org.hibernate.Query;
import   javax.servlet.http.HttpServletRequest;
import   javax.servlet.http.HttpServletResponse;
import   java.sql.*;
import   org.apache.struts.action.ActionForm;
import   org.apache.struts.action.ActionForward;
import   org.apache.struts.action.ActionMapping;
import   org.apache.struts.actions.DispatchAction;
import   org.apache.struts.action.Action;
import   com.jyx.UserList;
import   java.util.*;
import   com.jyx.UserListDAO;

/**  
  *   MyEclipse   Struts
  *   Creation   date:   12-31-2006
  *  
  *   XDoclet   definition:
  *   @struts.action   validate= "true "
  *   @struts.action-forward   name= "success "   path= "/success.jsp "   redirect= "true "
  */
public   class   UserAction   extends   DispatchAction   {

//   ---------------------   Instance   Variables

//   ---------------------   Methods

/**  
  *   Method   execute
  *   @param   mapping
  *   @param   form
  *   @param   request
  *   @param   response
  *   @return   ActionForward
  */
public   ActionForward   addUser(
ActionMapping   mapping,
ActionForm   form,
HttpServletRequest   request,
HttpServletResponse   response)   {

String   name   =   request.getParameter( "name ");
String   pass   =   request.getParameter( "password ");
System.out.println(name);
System.out.println(pass);
try
{
       
UserList   userlist   =   new   UserList();
userlist.setUserName(name);
userlist.setPassWord(pass);
userlist.setUserType(new   Integer(1));
userListDAO.save(userlist);

}catch(Exception   e)
{
e.printStackTrace();
}
return(mapping.findForward( "success "));
}
private   UserListDAO   userListDAO;
public   void   setUserListDAO(UserListDAO   userListDAO)
{

this.userListDAO   =   userListDAO;
}
   
}

前台的JSP文件。

    <%@   page   language= "java "   contentType= "text/html;charset=GB2312 "   %>
<%
request.setCharacterEncoding( "GB2312 ");
response.setHeader( "Cache-Control ", "no-cache ");   //HTTP   1.1
response.setHeader( "Pragma ", "no-cache ");   //HTTP   1.0
response.setDateHeader   ( "Expires ",   -1);
response.setDateHeader( "max-age ",   0);
%>
<html   >
<head>


<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 "   />
<title> 黑马后台管理系统   </title>
<script   language= "JavaScript ">

function   susername()
{
  document.forms[0].name.focus();
}
function   check()
{
var   obj   =   document.forms[0];
if((obj.name.value   == " ")||(obj.name.value.length <1))
{
alert( "用户名不能为空 ");  
obj.name.focus();

}
else   if((obj.password.value== " ")||(obj.password.value.length) <1)
{
      alert( "密码不能为空 ");
      obj.password.focus();
      }
  else
      obj.submit();  
}
</script>


</head>

<body   onLoad= "susername() ">
<form   action= "./user.do?method=addUser "   method= "post ">
请输入用户名: <input   type= "text "   name= "name "/> <br>
请输入密码: <input   type= "password "   name= "password "> <br>
<input   type= "button "   value= "提交 "   onClick= "check() "/> &nbsp;&nbsp; <input   type= "reset "   value= "重置 "/>
</form>


</body>
</html>

为什么点提交之后,说找不到action但是只用struts+hiberante时就可以插入数据。高手救小弟一命吧。。。。。。

[解决办法]
你的web.xml配置了吗,关于spring
[解决办法]
hibernate.cfg.xml
看看里面关于UserList.hbm.xml文件的配置(主要是看路径)
[解决办法]
<form action= "./user.do?method=addUser " method= "post ">
把.去掉
[解决办法]
web.xml是不需要配任何和spring有关的东西的
------


别胡说啊
[解决办法]
shenglijay(探索者) 这个说的没错,web.xml有structs配置了,就不用spring的监听器了

热点排行