现在有页面index.jsp
<%@ page contentType="text/html; charset=gb2312" %>
<%request.setCharacterEncoding("gb2312"); %>
<%String str=request.getParameter("str");%>
<html>
<head>
<title>jsp界面-接受一个参数</title>
</head>
<body>
<jsp:include flush="true" page="xxx"/>
<%=str%>
</body>
</html>还有一个servlet 名字和URL都是xxx,什么都没有,也只接受一个参数xxx并输出
package hospital.servlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class xxx extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK"; //Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
request.setCharacterEncoding("gb2312");
String servletstr=request.getParameter("xxx");
out.println(servletstr);
} //Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
} //Clean up resources
public void destroy() {
}
}现在假设我们随便给一个参数indexjsp?str=jsp&xxx=servlet为什么这样输入两个?意思也就是如果用jsp:include的话servlet也可以接受到参数????
<%@ page contentType="text/html; charset=gb2312" %>
<%request.setCharacterEncoding("gb2312"); %>
<%String str=request.getParameter("str");%>
<html>
<head>
<title>jsp界面-接受一个参数</title>
</head>
<body>
<jsp:include flush="true" page="xxx"/>
<%=str%>
</body>
</html>还有一个servlet 名字和URL都是xxx,什么都没有,也只接受一个参数xxx并输出
package hospital.servlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;public class xxx extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK"; //Initialize global variables
public void init() throws ServletException {
} //Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
request.setCharacterEncoding("gb2312");
String servletstr=request.getParameter("xxx");
out.println(servletstr);
} //Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
} //Clean up resources
public void destroy() {
}
}现在假设我们随便给一个参数indexjsp?str=jsp&xxx=servlet为什么这样输入两个?意思也就是如果用jsp:include的话servlet也可以接受到参数????
这个是设置
<jsp:include ../> 的特殊参数的!
当然, include 里面可以使用调用者index.jsp的参数