2014-01-10 69 views
1

我正在寫一個簡單的形式採取姓名Struts2的JavaBeans和二傳手

這是我的index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%> 
<%@ taglib prefix="s" uri="/struts-tags" %>  
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Form di inserimento</title> 
</head> 
<body> 
    <h1>Inserisci il tuo nome e il tuo cognome</h1> 
    <s:form action="Form"> 
     <s:textfield name="nome" label="il tuo nome"/> 
     <s:textfield name="cognome" label="il tuo cognome"/> 
     <s:submit/> 
    </s:form> 
</body> 
</html> 

這是我ResultForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"%> 
<%@ taglib prefix="s" uri="/struts-tags" %> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Risultato della form</title> 
</head> 
<body> 
    <h1><s:property value="customPage"/></h1> 
</body> 
</html> 

和這是我的動作類

package com.paolo; 

import com.opensymphony.xwork2.ActionSupport; 

@SuppressWarnings("serial") 
public class Form extends ActionSupport { 
    private static final String GREETINGS = "Congratulazioni "; 
    private String nome; 
    private String cognome; 
    private String customPage; 

    public String getNome() { 
     return nome; 
    } 

    public void setNome(String nome) { 
     this.nome = nome; 
    } 

    public String getCognome() { 
     return cognome; 
    } 

    public void SetCognome(String cognome) { 
     this.cognome = cognome; 
    } 

    public String getCustomPage() { 
     return customPage; 
    } 

    public void setCustomPage(String customPage) { 
     this.customPage = customPage; 
    } 

    public String execute() { 
     setCustomPage(GREETINGS + " " + getNome() + " " + getCognome()); 
     return SUCCESS; 
    } 

} 

這一切都確定,但cognome(=姓)是集爲空時,我的ResultForm.jsp 感謝去幫助

回答