gpt4 book ai didi

java - Struts2 javabean 和 setter

转载 作者:行者123 更新时间:2023-11-30 04:04:41 25 4
gpt4 key购买 nike

我正在写一个简单的表格来获取名字和姓氏

这是我的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>

这是我的 Action 类

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;
}

}

一切都好,但是当我进入 ResultForm.jsp 时,cognome(= 姓氏)被设置为 null感谢您的帮助

最佳答案

setter 的名称应该是 setCognome 而不是 SetCognome,这样 struts2 才能正确填充 bean。

http://en.wikibooks.org/wiki/Java_Programming/JavaBeans

关于java - Struts2 javabean 和 setter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21043238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com