我想在使用NetBeans 7.4的Struts中獲取用戶輸入。有兩個.jsp文件,用戶輸入文本的welcomeStruts.jsp文件和另一個用於顯示文本的index.jsp文件。問題是:我需要使用哪個標籤庫來處理用戶輸入?在Struts1的,它工作時,標籤庫前綴=「S」 URI =「/ Struts的標籤」共設置了再處理用戶輸入的是這樣的代碼:如何通過Struts獲得簡單的用戶輸入?
的Hello World,<s:property value="name"/>
它不在Struts2中工作。我在Struts2中包含哪些taglib?如何從welcomeStruts.jsp獲取用戶輸入以顯示在index.jsp中?謝謝。
welcomeStruts:
<%@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仍然有效。 – 2015-01-09 20:08:05