我是Struts2的新手。我遇到了一个问题:
According to the TLD or the tag file, attribute name is mandatory for tag text
我的JSP文件是
<%@ taglib uri="/struts-tags" prefix="html"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<body>
<h2 style="color:red;"><% if(request.getParameter("msg")!=null) {
out.println(request.getParameter("msg"));
}%></h2>
<h1 class="welcome">Login To Your Account</h1>
<div style="align-items: center;margin-left:200px;font-size:20px;white-space:pre;">
<html:form action="/loginsuccess">
UserName <html:text style="height:30px;width:300px;padding:10px;" property="username" /><br><br>
PassWord <html:password style="height:30px;width:300px;padding:10px;" property="password"/><br><br>
<input type ="submit" value="Log in" /><br><br>
New User ? <a href="signup.jsp">Signup</a>
</html:form>
</div>
</body>
</html>
所以这给了我一个错误
org.apache.jasper.JasperException: /login.jsp (line: 44, column: 10) According to the TLD or the tag file, attribute name is mandatory for tag text
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:237)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:859)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1538)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2375)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2427)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:895)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1538)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2375)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2427)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2433)
org.apache.jasper.compiler.Node$Root.accept(Node.java:474)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2375)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1817)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:96)
我应该在文本标签中添加更多内容吗?
答案 0 :(得分:0)
taglib定义适用于Struts2,但JSP代码适用于Struts1。您不能将TLD从一个框架替换为另一个框架,因此代码将无法工作。
在Struts2中,我们通常使用s:
命名前缀以区分框架,但如果您愿意,可以使用旧的preifix,但是应该重写代码以使用新的标记库。
<%@ taglib uri="/struts-tags" prefix="html"%>
如果您需要帮助将Struts1应用程序迁移到Struts2,您应该阅读Migration from Struts 1 to Struts 2。