【问题标题】:JSP Syntax error when trying to embed a a-href尝试嵌入 a-href 时出现 JSP 语法错误
【发布时间】:2016-08-09 05:10:44
【问题描述】:

我的网络应用程序有这个 JSP 代码:

我在成功子句中的"<a href="welcome.html">Delete</a>" 处收到语法错误。谁能帮我查明问题?谢谢,不胜感激!

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>atozknowledge.com demo loginjsp</title>
</head>
<body>
    <%@ page import="java.sql.*"%>
    <%@ page import="javax.sql.*"%>
    <%
String userid=request.getParameter("usr"); 
session.putValue("userid",userid); 
String pwd=request.getParameter("pwd"); 
Class.forName("com.mysql.jdbc.Driver"); 
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/tomcat","root","root"); 
Statement st= con.createStatement(); 
ResultSet rs=st.executeQuery("select * from users where userid='"+userid+"'"); 
if(rs.next()) 
{ 
if(rs.getString(2).equals(pwd)) 
{ 
out.println("welcome"+userid); 
<a href="welcome.html">Delete</a>


} 
else 
{ 
out.println("Invalid password try again"); 
} 
} 
else 
%>
<a href="index.html">Home</a>
</body>
</html>

【问题讨论】:

  • 如果您不打算自己回答问题,请不要发表评论。我不在乎它是否可怕,我不想要你的建议。谢谢,拜拜。 @BalusC

标签: java jsp tomcat servlets


【解决方案1】:

&lt;a href="welcome.html"&gt;Delete&lt;/a&gt; 不是有效的 Java 代码。如果你想退出 Java scriptlet,使用%&gt; 这样做(然后&lt;% 回到它):

%><a href="welcome.html">Delete</a><%

【讨论】:

    【解决方案2】:

    您的标签被插入到代码的 Java 部分中。只需移动您的标签或关闭您的脚本

    if(rs.getString(2).equals(pwd)) 
    { 
    out.println("welcome"+userid); 
    %>
    <a href="welcome.html">Delete</a>
    <%
    
    } 
    else 
    { 
    out.println("Invalid password try again"); 
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-15
      • 2012-03-21
      • 2017-12-11
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多