有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

jsp文件“找不到符号:变量a位置:类SimpleFiedJSPervlet”中的java编译错误

我正在努力学习会话隐式对象。请查收。在index.jsp中,我创建了一个表单。单击提交按钮,它将重定向到welcome.jsp。在welcome.jsp中,我正在创建会话属性,在同一页面中,我们重定向到second.jsp。秒。jsp我们将通过会话获取名称。但是在welcom。jsp文件出现错误。找不到符号:变量a位置:class SimpleFiedJSPervlet

enter image description here

索引。jsp

 <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
               <h1> This for getting session implicit object </h1>
                <form action="welcome3.jsp">
                    <input type="text" name="uname">
                    <input type="submit" value="go"><br/>                    
                </form>                
        </body>
    </html>

欢迎。jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
         <% 
             String name=request.getParameter("uname");
             out.print("Welcome"+name);
             session.setAttribute("user", name);
             <a href ="second.jsp" > second jsp  </a>
         %>
    </body>
</html>

其次。jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <% 
            String name=(String )session.getAttribute("user");
        %>
    </body>
</html>

网络。xml

<web-app>
    <error-page>
        <error-code> 500</error-code>
        <location> /error.jsp</location>
    </error-page>
</web-app>

共 (1) 个答案

  1. # 1 楼答案

    java代码中有html标记

         <% 
             String name=request.getParameter("uname");
             out.print("Welcome"+name);
             session.setAttribute("user", name);
              <a href ="second.jsp" > second jsp  </a> // html anchor tag
         %>
    

    应该在它之外

    <a href ="second.jsp" > second jsp  </a>
    

    what are scriptlets in jsp?