First of all, your html source code is incomplete. the <head> and <body> tags are missing from both of your jsp files. So the result of these jsp pages will be incorrect.
WILLIAMBALDWIN wrote:
请问使两个jsp页面能传值有没有什么要求? 是不是两个页面必须通过form表单的action联系在一起
Now to answer your question here, I need to mention some of ideas of how Servlet and JSP sharing the data between pages.
There are 3 well-known containers that can be used to save data, they are:
- ServletRequest
- HttpSession
- ServletContext
All the above objects provide a get/setAttribute methods.
In the case here, you are using the implicit JSP variable request (Refers to the current request to the page) as the container to save date. You should be aware of the objects shared using request are accessible only for the life if a request.
Now think about the HTTP protocol, based on HTTP request and response, you have established a TCP connection with a 3 handshake and HTTP protocol has a request to your JSP page. Because you set an attribute in one JSP page, in order to let another JSP page knows this attribute, you need to forward this request to the second JSP page using a special jsp tag.
<jsp:forward page="/index.jsp" />
Another option is to use the HTTP session as a container.
String str=(String)session.getAttribute("msg"); // session is an implicit JSP variable
Of course you can think about using a ServletContext as well.
WILLIAMBALDWIN wrote:
是不是两个页面必须通过form表单的action联系在一起
Nope, this is not required.
Hope this helps.
Regards,
Jiafan