2013-03-22 3 views
0

나는이 양식을 가지고 그것을 처리 할과 콩 방법과 형태 :JSP - 프로세스 하나 개 이상의 매개 변수

<form id="myForm" class="form-horizontal" action="/user" method="post"> 
    <fieldset> 
    <div class="control-group"> 
     <!-- Text input--> 
     <label class="control-label" for="input01">Email:</label> 
     <div class="controls"> 
     <input name="email" placeholder="email" class="input-xlarge" type="text" 
      value="<%=?????????"> 
     </div> 
    </div> 

    <div class="control-group"> 
     <!-- Text input--> 
     <label class="control-label" for="input01">Password:</label> 
     <div class="controls"> 
     <input name="password" placeholder="password" class="input-xlarge" type="text" 
      value="<%=request.getParameter("password")%>"> 
     </div> 
    </div> 
    </fieldset> 
</form> 

</div> 

<div class="modal-footer"> 
    <a href="#" class="btn" data-dismiss="modal">Close</a> 
    <input class="btn btn-primary" type='button' value='Save Changes' 
     onclick='document.forms["myForm"].submit();'> 
</div> 

</div> 

을 그러나, 나는 두 개의 매개 변수와 콩 방법이 있고 나는 이것을 처리하기 위해 시도 사용하여 :

public void insert(String email, String password) { 
    User entry = new User(email, password); 
    PersistenceManager pm = PMF.get().getPersistenceManager(); 
    pm.makePersistent(entry); 
} 

내 질문은 두 개의 매개 변수를 사용하는 폼과 제대로 연결하는 방법입니다.

+0

같은 유사합니다 중간과 끝에는 타의 추종을 불허하는 "end div"태그가 있습니다. –

답변

0

두 가지를 연결하기 위해 bean java 파일을 만들었습니까? 기능성 콩 파일은 다음 세 부분으로 구성

  1. 초기화
  2. 게터
  3. 세터 다음 줄에

로 일하고 생성자, 당신은 형태에 관한 일반 예를 찾을 수 위에 게시 한 사람을 기반으로합니다. System.out.println의 오래된 트릭을 기억하여 작성한 모든 내용이 올바른지 확인하십시오.

콩 파일,의 그것은 다른 한편으로

package blabla; 

import java.io.Serializable; 

public class UserData implements Serializable { 

private String email; 
private String password; 

//1.Constructor 
public UserData() 
{ 
    email=""; 
    password=""; 

} 

//2.Getters 
public String getEmail(){ 
return email; 
} 

public String getPassword(){ 
return password; 
} 

//3.Setters - Caution: we use different variables here 

public void setEmail(String eml) 
{ 
this.email=eml; 
} 

public void setPassword(String pswd) 
{ 
this.password=pswd; 
} } 

을 userData.java 부르 자의 .jsp로 파일은 두 가지가이 index.jsp를

<%--Blablabla headers and stuff, I will only write the things needing to be added--%> 
<jsp:useBean id="entry" class="packagePath.UserData" scope="application"/> 
<%--For analytic info about the parameters of the jsp call above, check:   http://www.javatpoint.com/jsp-useBean-action--%> 
<jsp:setProperty name="entry" property="*"/> 
<%--Code to invoke all the setters of the bean--%> 
<p><jsp:getProperty name="entry" property="email"/></p> 
<p><jsp:getProperty name="entry" property="password"/></p> 
<%--The two lines are not obligatory to use; you will need them only if you wan tto print the results on the page--%> 
<%-- rest of the code%--> 
+0

범위 사용에 특히주의하십시오! 다른 페이지에서 여러 빈을 사용하는 경우 "응용 프로그램"태그를 사용하는 것이 금지됩니다. 범위에 대한 옵션은 page, request, session 및 application입니다. – brbtsl

관련 문제