Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java EE (J2EE) и Spring > request


Автор: fics 31.3.2008, 14:22
Объесните пожалуйста как сделать чтобы при активизации этой страницы этот метод:
Код

 identificationManager.registrationClient((Clients)registrationForm);
 
срабатывал только после Request
Код

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="shop.IdentificationManager" %>
<%@ page import="tables.Clients" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<jsp:useBean id="registrationForm" class="forms.RegistrationForm" scope="request">
    <jsp:setProperty name="registrationForm" property="*"/>
</jsp:useBean>

<%
  WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
  IdentificationManager identificationManager = (IdentificationManager)ctx.getBean("identificationManager");
  identificationManager.registrationClient((Clients)registrationForm);
%>

<html>
  <head><title>Welcome to shop</title></head>
  <body>

    <form name="registrationForm" method="POST">

..................................................


PS Форма "сабмитится сама на себя"

что то вроде: if(был request){значит выполняется  identificationManager.registrationClient((Clients)registrationForm);}

Автор: Kangaroo 31.3.2008, 15:24
Цитата(fics @  31.3.2008,  13:22 Найти цитируемый пост)
срабатывал только после Request

А она может срабатывать без реквеста?  smile 

Автор: fics 31.3.2008, 15:32
Ну да она срабатывает сразу когда пользователь загодит на регистрацию, только объект registrationForm имеет все поля равные = null

Автор: v2v 31.3.2008, 19:01
request != null 
пробывал? 

или какой то из методов класса HttpServletRequest ? 
Код

  isRequestedSessionIdFromCookie()
    Checks whether the session id specified by this request came in as a cookie. 
 isRequestedSessionIdFromURL()
    Checks whether the session id specified by this request came in as part of the URL. 
 isRequestedSessionIdFromUrl()
    Checks whether the session id specified by this request came in as part of the URL. Deprecated. 
 isRequestedSessionIdValid()
    Checks whether this request is associated with a session that is valid in the current session context.


Автор: fics 31.3.2008, 20:37
Цитата(v2v @  31.3.2008,  19:01 Найти цитируемый пост)
request != null пробывал? 

Нет по другому

Автор: v2v 31.3.2008, 21:32
ну так напиши как.

Автор: fics 31.3.2008, 22:45
Код

package shop;

import Dao.ShopDao;
import forms.EnterForm;
import forms.RegistrationForm;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class IdentificationManager {
    private ShopDao shopDao;
    private String Errormsg;

    public void setShopDao(ShopDao shopDao) {
        this.shopDao = shopDao;
    }


    public String getErrormsg() {
        return Errormsg;
    }

    public void setErrormsg(String Errormsg) {
        this.Errormsg = Errormsg;
    }
    

    public void registrationClient(RegistrationForm registrationForm, HttpServletResponse response)
        throws IOException {
            if (registrationForm.getCity().equals("") || registrationForm.getAddress().equals("") ||
                registrationForm.getMail().equals("") || registrationForm.getLogin().equals("") ||
                registrationForm.getPassword().equals("") || registrationForm.getConfirmpass().equals("")) {
                setErrormsg("Пожалуйста заполните все поля формы");
            } else {
                shopDao.insertClient(registrationForm);
                response.sendRedirect("login.jsp?shop=ok");
        }
    }


    public void enterClient(EnterForm enterForm, HttpServletResponse response)
        throws IOException {
            if(!enterForm.getLogin().equals("") || !enterForm.getPassword().equals("")) {
                if(shopDao.clientFoundDb(enterForm) > 0){
                    response.sendRedirect("shop.jsp");
                } else {
                }
            }

    }

}



Код

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="org.springframework.web.context.WebApplicationContext" %>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@ page import="shop.IdentificationManager" %>
<%@ page import="tables.Clients" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>


<jsp:useBean id="registrationForm" class="forms.RegistrationForm" scope="request">
    <jsp:setProperty name="registrationForm" property="*"/>
</jsp:useBean>



<%
  WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
  IdentificationManager identificationManager = (IdentificationManager)ctx.getBean("identificationManager");
  identificationManager.registrationClient(registrationForm,response);
%>

<%=identificationManager.getErrormsg()%>

<html>
  <head><title>Welcome to shop</title></head>
  <body>

    <form name="registrationForm" method="post">
.................................................................................

Автор: fics 1.4.2008, 11:37
Сабмит ведь тоже передается аналогично текстовому поля, поэтому можно сделать так:
Код



if (request.getParameter("reg") != null) {
      if (!registrationForm.validate()) {
     ..................................................... 
     }


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)