请问我一点按钮怎么就挂了呢????
说明:在A.html中点击个按钮,通过window.open跳到B.jsp。目前A.html和B.jsp 单独访问都好用,请问问题在哪里呢??
下面是主要的代码
A.html
<script type="text/javascript">
function openBpage(){
window.open("/openpage", '_blank');
}
</script>
<body>
<form name="indexPage" method="POST">
<H1>this A Page</H1>
<a>click the button to get the number</a>
<input type="button" value="open B page" onclick="openBpage();">
<input type="hidden" name="testNumber" value="123">
</form>
</body>
</html>
web.xml
<display-name>testweb1</display-name>
<servlet>
<servlet-name>openpage</servlet-name>
<servlet-class>org.testweb1.OpenPage</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>openpage</servlet-name>
<url-pattern>/openpage</url-pattern>
</servlet-mapping>
</web-app>
openpage.java
package org.testweb1;--------------------编程问答-------------------- 有没有报错信息? --------------------编程问答-------------------- 你把
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class OpenPage
*/
@WebServlet("/OpenPage")
public class OpenPage extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public OpenPage() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// request.getRequestDispatcher("/B.jsp").forward(request, response);
getServletConfig().getServletContext().getRequestDispatcher("/B.jsp").forward(request, response);
}
}
getServletConfig().getServletContext().getRequestDispatcher("/B.jsp").forward(request, response);
写在doGet方法里面看看,window.open(),提交方式只能是get,所有会调doGet方法, --------------------编程问答--------------------
忘了不好意思
--------------------编程问答--------------------
改成下面的样子也不行。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {--------------------编程问答-------------------- window.open的请求调用的是doGet方法
// TODO Auto-generated method stub
doPost(request,response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
// request.getRequestDispatcher("/B.jsp").forward(request, response);
getServletConfig().getServletContext().getRequestDispatcher("/B.jsp").forward(request, response);
}
路径改为window.open("openpage", '_blank'); --------------------编程问答-------------------- 你看你后来跳转的URL是不是少了项目名。。 --------------------编程问答-------------------- 5楼的应该对的 --------------------编程问答-------------------- 五楼的应该没问题了 要是还不正确 请把目录结构发上来看看 --------------------编程问答-------------------- 把自己的工程名加上去,如:/project/openpage, 你试试看
补充:Java , Web 开发