如何在不使用JavaScript的情况下在Java Struts中显示消息框 [英] How to display message box in java struts without use javascript

查看:65
本文介绍了如何在不使用JavaScript的情况下在Java Struts中显示消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

如何在java struts的Action类中显示消息.
例如:我的页面有一个文本框和一个按钮,当用户单击按钮时,它将在Action类上调用一个函数(checkValue),如果文本框为空,则显示消息框此字段不为空"

在这种情况下,我有3层:view/page1.jsp
动作/Page1Action.java
form.Page1Form.java


请帮助我


Hi all,

How to display message in Action class of java struts.
Ex: My page have a textbox and a button, when user click on button, It will call a function(checkValue) on Action class, if textbox is empty, show message box "this field is not empty"

in this case I have 3 tier: view/page1.jsp
action/Page1Action.java
form.Page1Form.java


please help me


thank in advance.

推荐答案

如果通过消息表示您是警报,我认为这是不可能的.

但是,如果您的JSP中有一个HTML字段(在您的情况下为Page1),则可以在其中设置操作消息(例如,为了清楚起见,JSP中也包含表单):

If by message you mean an alert, I don''t think that''s possible.

If, however, you have an HTML field in your JSP (Page1 in your case), you can set the action message there, for instance (also included form in your JSP for clarity):

<form id="Page1Form" method="POST" action="Page1.action">
    <div class="info">
        <s:property value="message" xmlns:s="#unknown" />
    </div>
</form>



然后,在您的Struts动作类中:



And then, in your Struts action class:

public class Page1 extends ActionSupport {
	/*This is what you will see in your message field*/
	private String message = "Fail";
	
	@Override
	public String execute() {
		try {
			/*Do your stuff*/
			
			/*Set message to what you want to output*/
			message = "OK";			
			/*Return result of your processing*/
			return SUCCESS;
		} catch(SomeException exception) {
			/*Set message to describe error*/
			message = "Some exception occurred";
			/*Return result of your processing, in this case error*/
			return ERROR;
		}
	}



然后,在执行时,字段



Then, upon execution, the value of the field

<s:property value="message" xmlns:s="#unknown" />

将使用您的Page1类中的"message"变量的值完成

will be completed with the value of the ''message'' variable in your Page1 class


这篇关于如何在不使用JavaScript的情况下在Java Struts中显示消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆