1

我有以下逻辑 index.jsp ->redirect sigin.jsp -> SigninController -> admin_site.jsp 或 user_site.jsp -> MultiActionController (AdminController or UserController)

问题出现在 AdminController (a MultiActionController) 中,因为我无法读取请求参数。我究竟做错了什么?我应该怎么办?

<bean id="placeholderConfig"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location"
        value="WEB-INF/classes/imperialii-servlet.properties" />
</bean>

<bean id="entranceController" class="ro.imperialii.controller.EntranceController">
    <property name="utilizator">
        <ref bean="utilizator"/>
    </property>
</bean>
<bean id="utilizator" class="ro.imperialii.model.Utilizator" />
<bean id="utilizatorValidator" class="ro.imperialii.model.UtilizatorValidator" />
<bean id="utilizatorMngr" class="ro.imperialii.model.UtilizatorManager" />
<bean id="proprietateMngr" class="ro.imperialii.model.ProprietateManager" />
<bean id="tipdeproprietateMngr" class="ro.imperialii.model.Tip_de_proprietate_Manager" />
<bean id="signinFormController" class="ro.imperialii.controller.SignInController" >
    <!-- 
    <property name="sessionForm"><value>true</value></property>
    <property name="commandName"><value>logonForm</value></property>
    <property name="commandClass"><value>ro.imperialii.model.Utilizator</value></property>
    <property name="validator"><ref bean="utilizatorValidator"/></property>
    <property name="formView"><value>signin</value></property>
    -->
    <property name="sessionForm" value="true"/>
    <property name="commandName" value="user"/>
    <property name="commandClass" value="ro.imperialii.model.Utilizator"/>
    <property name="utilizatorManager">
        <ref bean="utilizatorMngr"/>
    </property>
    <property name="proprietateManager">
        <ref bean="proprietateMngr"/>
    </property>
    <property name="tip_de_proprietate_Manager">
        <ref bean="tipdeproprietateMngr"/>
    </property>
</bean>
<bean id="adminFormController" class="ro.imperialii.controller.AdminController" >
    <property name="utilizatorManager">
        <ref bean="utilizatorMngr"/>
    </property>
    <property name="tip_de_proprietate_Manager">
        <ref bean="tipdeproprietateMngr"/>
    </property>
    <property name="myutilizator">
        <ref bean="utilizator"/>
    </property>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <props>
            <prop key="/signin.htm">signinFormController</prop>
            <prop key="/admin/*.htm">adminFormController</prop>
            <!--
            <prop key="/signin.htm">signinFormController</prop>
            -->
        </props>
    </property>
</bean>

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename"><value>messages</value></property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
    <property name="prefix"><value>/WEB-INF/jsp/</value></property>
    <property name="suffix"><value>.jsp</value></property>
</bean>


<!-- Database Resources and Transaction Management -->
<!--
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url"
        value="jdbc:mysqlql://localhost:3306/imperialii" />
    <property name="username" value="root" />
    <property name="password" value="" />
</bean>
<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="useTransactionAwareDataSource" value="false" />
    <property name="mappingResources">
        <list>
            <value>Utilizator.hbm.xml</value>
            <value>Proprietate.hbm.xml</value>
            <value>Tip_de_proprietate.hbm.xml</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="connection.pool_size">1</prop>
            <prop key="hibernate.dialect">
                org.hibernate.dialect.MySQL5Dialect
            </prop>
            <prop key="show_sql">true</prop>
            <prop key="hibernate.generate_statistics">true</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">
                false
            </prop>
        </props>
    </property>
</bean>
-->

我的 admin_site.jsp:

<form:form method="post">
<div id="left">

<div id="sub_left">

<h3>Utilizator</h3>
<p> Nume utilizator </br>
<input id="nume_utilizator" type="text" style="width:100%; max-width: 160px;" name="nume_utilizator">
<p> Numele de familie </br>
<input id="nume" type="text" style="width:100%; max-width: 160px;" name="nume">
<p> Prenumele </br>
<input id="prenume" type="text" style="width:100%; max-width: 160px;" name="prenume">
<p> Numarul de telefon personal </br>
<input id="telefon_personal" type="text" style="width:100%; max-width: 160px;" name="telefon_personal">
<p> Numarul de telefon al firmei </br>
<input id="telefon_firma" type="text" style="width:100%; max-width: 160px;" name="telefon_firma">
<p> Parola </br>
<input id="parola" type="password" style="width:100%; max-width: 160px;" name="parola">
<p> Status activ/inactiv </br>
<select name="status">
    <option name="activ" value="activ">ACTIV</option>
    <option name="inactiv" value="inactiv">INACTIV</option>
</select>
<p> Actiuni </br>
<!--
<button id="insereaza_modifica" type="button" name="insereaza_modifica">Insereaza / Modifica</button> 
-->
<a href="admin/insereaza_u.htm">Insereaza</a></br>
<a href="admin/sterge_u.htm">Sterge</a></br>
<a href="admin/modifica_u.htm">Modifica</a>
</div>

另一个奇怪的事实是,我第一次单击 insereaza_u.htm 并重新显示页面,但是当我第二次单击 modifica_u.htm 时,请求行变为:localhost/imperialii/admin/admin/modifica_u.htm(注意 2 admin小路)

AdminController 来了:

public class AdminController extends MultiActionController {
    protected final Log logger = LogFactory.getLog(getClass());
    private UtilizatorManager utilizatorManager;
    private Tip_de_proprietate_Manager tip_de_proprietate_Manager;
    private Utilizator myutilizator;
    private String nume;
    private String prenume;
    private String nume_de_utilizator;
    private String parola;
    private String numar_tel_personal;
    private String numar_tel_firma;
    private String status_utilizator;

    public ModelAndView insereaza_u(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("insereaza_u method called");
        nume = request.getParameter("nume");
        prenume = request.getParameter("prenume");
        nume_de_utilizator = request.getParameter("nume_utilizator");
        parola = request.getParameter("parola");
        numar_tel_personal = request.getParameter("telefon_personal");
        numar_tel_firma = request.getParameter("telefon_firma");
        status_utilizator = request.getParameter("status");
        logger.info("insereaza Request nume_utilizator " + nume_de_utilizator);
        logger.info("insereaza Request status " + status_utilizator);
        logger.info("insereaza Request ContextPath " + request.getContextPath());

        Map myMap = request.getParameterMap();

        Iterator entries = myMap.entrySet().iterator();
        while (entries.hasNext()) {
          Entry thisEntry = (Entry) entries.next();
          Object key = thisEntry.getKey();
          logger.info("insereaza Map Request Parameter " + key.toString());
          Object value = thisEntry.getValue();
          logger.info("insereaza Map Request Value " + value.toString());
          // ...
        }


        myutilizator.setNume(nume);
        myutilizator.setPrenume(prenume);
        myutilizator.setNume_de_utilizator(nume_de_utilizator);
        myutilizator.setParola(parola);
        myutilizator.setNumar_tel_personal(numar_tel_personal);
        myutilizator.setNumar_tel_firma(numar_tel_firma);
        myutilizator.setStatus_utilizator(status_utilizator);

        //utilizatorManager.saveUtilizator(myutilizator);
        myMap = listEntities();
        //return new ModelAndView("admin_site", "message", "Add method called");
        return new ModelAndView("admin_site", "model", myMap);
    }



    public ModelAndView modifica_u(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        System.out.println("modifica_u method called");
        return new ModelAndView("admin_site", "message", "Remove method called");
    }

提前感谢您的任何建议!

4

0 回答 0