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

请问一个用S2SH注册的有关问题

2012-03-15 
请教一个用S2SH注册的问题我用S2SH整合,弄一个注册的小程序,但老提示说找不到路径,不知道怎么回事,各位帮

请教一个用S2SH注册的问题
我用S2SH整合,弄一个注册的小程序,但老提示说找不到路径,不知道怎么回事,各位帮我看看吧。
下面是regist.jsp

Java code
${user.msg}   <s:form action="regist" method="post">           用户名:<s:textfield name="user.username" size="20"/><br/>           密码:<s:password name="user.userpassword" size="20"/><br/>           <s:submit value="注册"/>   </s:form>

下面是web.xml
XML code
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4"     xmlns="http://java.sun.com/xml/ns/j2ee"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">    <filter>        <filter-name>struts2</filter-name>        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>    </filter>        <filter-mapping>        <filter-name>struts2</filter-name>        <url-pattern>/*</url-pattern>    </filter-mapping>        <listener>        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>    </listener>        <context-param>        <param-name>contextConfigLocation</param-name>        <param-value>classpath:applicationContext.xml</param-value>    </context-param>      <welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list></web-app>

下面是application.xml
XML code
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">    <property name="configLocation">        <value>classpath:hibernate.cfg.xml</value>    </property>    </bean>        <bean id="userDAOImpl" class="dao.UserDAOImpl">        <property name="sessionFactory">            <ref local="sessionFactory"/>        </property>    </bean>        <bean id="userService" class="service.UserServiceImpl2">        <property name="userDAO">            <ref local="userDAOImpl"/>        </property>    </bean>        <bean id="Regist" class="action.Regist">        <property name="userService">            <ref local="userService"/>        </property>    </bean>

下面是struts.xml
XML code
<struts>    <constant name="struts.devMode" value="true"/>    <package name="Regist11" extends="struts-default" namespace="/my">        <action name="regist" class="Regist">            <result name="success">/regist.jsp</result>                    </action>    </package></struts>


dao层
Java code
package dao;import java.util.List;import org.springframework.orm.hibernate3.support.HibernateDaoSupport;import entity.User;public class UserDAOImpl extends HibernateDaoSupport implements UserDAO {        public boolean exist(User user) {        System.out.println("正在验证数据......");        String hql="from User u where u.username='"+user.getUsername()+"'and u.userpassword='"+user.getUserpassword()+"'";        List userList=this.getHibernateTemplate().find(hql);        System.out.println("共找到数据:"+userList.size());        if(userList.size()>0&&userList!=null){            return true;        }else{        return false;        }    }    public void saveUser(User user) {        this.getHibernateTemplate().save(user);    }} 


下面是服务层
Java code
package service;import dao.UserDAO;import entity.User;public class UserServiceImpl2 implements UserService2 {        private UserDAO userDAO;        public UserDAO getUserDAO() {        return userDAO;    }    public void setUserDAO(UserDAO userDAO) {        this.userDAO = userDAO;    }    public boolean exist(User user) {        return userDAO.exist(user);    }    public void saveUser(User user) {        userDAO.saveUser(user);    }                        }

下面是实体类
Java code
package entity;import java.io.Serializable;public class User implements Serializable{    /**     *      */    private static final long serialVersionUID = 1L;        private String msg="";    private Integer userid;    private String username;    private String userpassword;    public Integer getUserid() {        return userid;    }    public void setUserid(Integer userid) {        this.userid = userid;    }    public String getUsername() {        return username;    }    public void setUsername(String username) {        this.username = username;    }    public String getUserpassword() {        return userpassword;    }    public void setUserpassword(String userpassword) {        this.userpassword = userpassword;    }    public String getMsg() {        return msg;    }    public void setMsg(String msg) {        this.msg = msg;    }    }

配置文件:
XML code
<?xml version="1.0"?><!DOCTYPE hibernate-mapping PUBLIC    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping package="entity">  <class name="User" table="WL_USER">  <!--定义id-->     <id name="userid" column="USERID">            <generator class="increment"/>        </id>      <!--定义用户名-->      <property name="username" type="string" column="USERNAME"/>      <!--定义密码-->       <property name="userpassword" type="string" column="PASSWORD"/>  </class></hibernate-mapping>

hibernate.cfg.xml
XML code
<!DOCTYPE hibernate-configuration PUBLIC    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <property name="hibernate.connection.url">jdbc:mysql://localhost/mytestdb</property>        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>        <property name="hibernate.connection.username">root</property>        <property name="hibernate.connection.password">root</property>        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>        <property name="hibernate.show_sql">true</property>                <mapping resource="entity/User.hbm.xml"/>    </session-factory></hibernate-configuration>

下面是action
Java code
package action;import service.UserService2;import com.opensymphony.xwork2.ActionSupport;import entity.User;public class Regist extends ActionSupport{        private String msg="";        private User user;        private UserService2 userService;        public User getUser() {        return user;    }    public void setUser(User user) {        this.user = user;    }    public UserService2 getUserService() {        return userService;    }    public void setUserService(UserService2 userService) {        this.userService = userService;    }        public String execute() throws Exception {        if(userService.exist(user)){            msg="注册成功";            user.setMsg(msg);            userService.saveUser(user);        }else{            msg="注册失败";            user.setMsg(msg);        };        return "success";    }//    public String getMsg() {//        return msg;//    }    } 


我访问的路径是http://localhost:8080/testWeb/my/regist.jsp
但老是说找不到路径,怎么回事

[解决办法]
你的URL里面这个my是什么意思,,还有,你项目名称是testWeb,而你的发布名称是不是这个呢,,如果你没有改的话,那就是和项目名称一样。。

你可以在web.xml里面直接设置这个register.jsp为默认的页面也可以的啊。


话说,你访问http://localhost:8080/testWeb会出现404吗?
[解决办法]
首先想说的是访问action的格式是:http://localhost:8080/testWeb/my/regist.action或者是http://localhost:8080/testWeb/my/regist,而不是你所访问的http://localhost:8080/testWeb/my/regist.jsp

[解决办法]
Java code
${user.msg}   <s:form action="regist" method="post">           用户名:<s:textfield name="user.username" size="20"/><br/>           密码:<s:password name="user.userpassword" size="20"/><br/>           <s:submit value="注册"/>   </s:form> 

热点排行