hereandthere4387547
2016-11-18 23:43
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'dologin2.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<jsp:useBean id="myUsers" class="com.po.Users" scope="page"/>
<h1>setProperty动作元素的使用方法</h1>
<hr>
<!-- 根据表单自动匹配所有的属性 -->
<%--
<jsp:setProperty name="myUsers" property="*"/>
--%>
<!-- 根据表单匹配部分的属性 -->
<%--
<jsp:setProperty name="myUsers" property="username"/>
--%>
<!-- 跟表单无关通过手工赋值给属性 -->
<%--
<jsp:setProperty name="myUsers" property="username" value=“lisi” />
<jsp:setProperty name="myUsers" property="password" value=“1234ss”/>
--%>
<!-- 通过URL传参数给属性赋值 -->
<%--
<jsp:setProperty name="myUsers" property="username" param="mypass" />
--%>
<!-- 使用传统的表达式方式来获取用户名和密码 -->
<%--
用户名:<%=myUsers.getUsername() %><br>
密码:<%=myUsers.getPassword() %><br>
--%>
<!-- 使用getProperty方式获取用户名和密码 -->
用户名:<jsp:getProperty name="myUsers" property="username"/><br>
密码:<jsp:getProperty property="password" name="myUsers"/>
</body>
</html>
MyEclipse2016 跟着老师做的
<!-- 跟表单无关通过手工赋值给属性 -->这个出错。
<!-- 使用getProperty方式获取用户名和密码 -->
用户名:<jsp:getProperty name="myUsers" property="username"/><br>
密码:<jsp:getProperty property="password" name="myUsers"/>
这个获得的是null,怎么办
dologin2.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'dologin2.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<jsp:useBean id="myUsers" class="com.po.Users" scope="page"/>
<h1>setProperty动作元素的使用方法</h1>
<hr>
<!-- 根据表单自动匹配所有的属性 -->
<%--
<jsp:setProperty name="myUsers" property="*"/>
--%>
<!-- 根据表单匹配部分的属性 -->
<%--
<jsp:setProperty name="myUsers" property="username"/>
--%>
<!-- 跟表单无关通过手工赋值给属性 -->
<jsp:setProperty name="myUsers" property="username" value=“lisi” />
<jsp:setProperty name="myUsers" property="password" value=“1234ss”/>
<!-- 通过URL传参数给属性赋值 -->
<%--
<jsp:setProperty name="myUsers" property="username" param="mypass" />
--%>
<!-- 使用传统的表达式方式来获取用户名和密码 -->
<%--
用户名:<%=myUsers.getUsername() %><br>
密码:<%=myUsers.getPassword() %><br>
--%>
<!-- 使用getProperty方式获取用户名和密码 -->
用户名:<jsp:getProperty name="myUsers" property="username"/><br>
密码:<jsp:getProperty property="password" name="myUsers"/>
</body>
</html>
注释去了之后出现了如下错误
HTTP Status 500 - /dologin2.jsp (line: 40, column: 62) quote symbol expected
type Exception report
message /dologin2.jsp (line: 40, column: 62) quote symbol expected
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /dologin2.jsp (line: 40, column: 62) quote symbol expected
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:89)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:222)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:162)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:153)
org.apache.jasper.compiler.Parser.parseSetProperty(Parser.java:897)
org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1118)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1434)
org.apache.jasper.compiler.Parser.parse(Parser.java:138)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:199)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:341)
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.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.56 logs.
Apache Tomcat/7.0.56
<!-- 跟表单无关通过手工赋值给属性 -->
<%--
<jsp:setProperty name="myUsers" property="username" value=“lisi” />
<jsp:setProperty name="myUsers" property="password" value=“1234ss”/>
--%>
把这段代码的注释去掉
JAVA遇见HTML——JSP篇
248277 学习 · 3071 问题
相似问题
回答 2
回答 2