in the servlet 's request to pass a domain object , so that the jsp page to accept , encountered a problem .
in the servlet , to achieve a jump page redirection and forwarding.
response.sendRedirect ("");
request.getRequestDispatcher ("path"). forward (request, response);
problems simplified as follows
servlet page :
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestSer extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.sendRedirect("../test1.jsp");
//request.getRequestDispatcher("../test1.jsp").forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
jsp page :
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'test1.jsp' starting page</title>
<script type="text/javascript" src="jquery.js"></script>
<script>
$(document).ready(function() {
alert("test");
});
function test() {
alert("test1");
}
</script>
</head>
<body>
<input type="button" value="按钮" onclick="test();" />
</body>
</html>
When redirecting it , jsp pages automatically pop-up warning , click the button, will pop up a warning.
However, when using the forward time , jsp page using jquery to write code does not automatically pop-up warning , click the button, will pop up a warning.
Because I want to remove the request jsp page value in the field , they have to use request.getRequestDispatcher ("../test1.jsp"). forward (request, response);
achieve forward , but as I did that jquery jsp pages written code can not execute , it is truly upset ! ! ! Do not understand why
------ Solution ------------------------------------- -------
I remember also encountered this problem. The workaround is to path problem. You try to adjust the path, in particular import jQuery path and see can do without .
------ Solution ---------------------------------------- ----
<script type="text/javascript" src="../jquery.js"></script>
such a change , all to try both .
------ For reference only -------------------------------------- -
with javascript tests found whether it is used to redirect or forward can be performed .
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'test1.jsp' starting page</title>
<script type="text/javascript" src="jquery.js"></script>
<script>
alert("test");
</script>
</head>
<body>
<input type="button" value="按钮" onclick="test();" />
</body>
</html>
jump to this page and can be printed !
------ For reference only -------------------------------------- -
moderator you think I should be on which path is appropriate
------ For reference only ---------------------- -----------------
various modifications such a change · · ·
------ For reference only ---------------------------------------
test under load it, should be able to
window.onload=function(){
alert("ok");
}
------ For reference only ----------------------------------- ----
I'm not jq not import correctly
------ For reference only ------------------------ ---------------
teach you one of the most simple and quick way :
page to embed an image object, and jQuery in the same directory.
then repeated testing , when forwarding , this image can be seen up , jQuery was properly introduced , of course, your "jsp page using jquery to write the code does not automatically pop-up warning " problem also gone.
------ For reference only -------------------------------------- -
I tried the next
entirely possible !
window.onload=function(){
alert("ok");
}
$(function(){
alert("kan........");
});
$(document).ready(function() {
alert("test");
});
------ For reference only ----------------------------------- ----
three kinds can be, you should have a path problem
------ For reference only --------------------- ------------------
jQuery itself is not treated underserved ?
------ For reference only -------------------------------------- -
${pageContext.request.contextPath}/..../jQuery.js absolute path to direct the whole jquery
------ For reference only ---------------------------- -----------
@ I remember also encountered this problem. The workaround is to path problem. You try to adjust the path, in particular import jQuery path and see can do without .
then do not know, now you 're saying now understand the meaning , in fact you should say : you open the page look at the source , click on the js file to see whether the open , they will understand Well the problem is here. Say you do not understand because we are too young , after all experience is not enough. Thank you withheld
没有评论:
发表评论