我正在使用Dynamic Web Project。 这是我的JSP代码。我正试图发送Hello to servlet从JSP发送数据到Servlet时发生错误
<%@ 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>Insert title here</title>
</head>
<body>
<jsp:include page="/servlet/ServletCode" flush="true" >
<jsp:param name="username" value="Hello" />
</jsp:include>
</body>
</html>
这是我的Servlet文件。
package pack.exp;
public class ServletCode extends HttpServlet
{
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String output= request.getParameter("username");
System.out.println(output);
PrintWriter pw = response.getWriter();
pw.println("Hello " + output);
}
}
在我的JSP文件中,我在这一行上得到了这个编译时错误。
片段 “/ servlet的/ ServletCode” 并没有在预期的路径/ JSpServletCode /的WebContent/servlet的/ ServletCode发现
请帮助我与此有关。
@阿保 感谢您的回复哥们。我在web.xml中进行了更改。 但现在作为输出我得到你好null。但输出应该是你好你好 – user3273473
好的。这意味着该参数不会去你的servlet。代码对我看起来很好。让我检查一下。 –
@一个保罗 是的确切 – user3273473