【发布时间】:2015-03-08 03:29:54
【问题描述】:
我正在尝试使用 NetBeans 7.4 在 Struts 中获取用户输入。有两个 .jsp 文件,welcomeStruts.jsp 用于用户输入文本,另一个文件 index.jsp 用于显示该文本。问题是:我需要使用哪个标签库来处理用户输入?在 Struts1 中,它在设置 taglib prefix="s" uri="/struts-tags" 然后像下面这样处理用户输入时工作:
世界你好,<s:property value="name"/>
它在 Struts2 中不起作用。我在 Struts2 中包含什么标签库?如何从 welcomeStruts.jsp 获取用户输入以显示在 index.jsp 中?谢谢。
欢迎Struts:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<html:html lang="true">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><bean:message key="welcome.title"/></title>
<html:base/>
</head>
<body style="background-color: white">
<logic:notPresent name="org.apache.struts.action.MESSAGE" scope="application">
<div style="color: red">
ERROR: Application resources not loaded -- check servlet container
logs for error messages.
</div>
</logic:notPresent>
<h3><bean:message key="welcome.heading"/></h3>
<p><bean:message key="welcome.message"/></p>
<p>Hello! This is the test welcome page for a Struts Web MVC project.</p>
<h1>Hello World From Struts2</h1>
<form action="hello">
<label for="name">Please enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="SUBMIT"/>
</form>
</body>
</html:html>
index.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-nested" prefix="f" %>
<html>
<body>
<H3>Welcome <html:text property="name"/>!</H3>
</body>
</html>
【问题讨论】:
-
这行不通,因为它是 Struts 1 代码。从 Struts1 代码迁移不是一项简单的任务,您必须重写 JSP。 Struts2 标签有不同的符号。但是,JSTL 和纯 html 仍然有效。