我做一个二次开发,我在想jsp不是能嵌套java代码吗,所以想在jsp页面写servlet类 但是不知道怎么调用,
(不要告诉我写在java里面,因为不行我才写到jsp页面)
在web.xml配置 通过
<servlet>
<servlet-name>testServlet</servlet-name>
<jsp-file>/jsp/test.jsp</jsp-file>
</servlet>
确实能访问到test.jsp 但是不会不调用doGet() doPost方法
--以下是test.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.esoon.cisiss.common.BaseServlet" %>
<%@ page import="java.io.IOException" %>
<%@ page import="javax.servlet.ServletException" %>
<%@ page import="javax.servlet.http.HttpServletRequest" %>
<%@ page import="javax.servlet.http.HttpServletResponse" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript">
alert("");
</script>
<%
class testServlet extends BaseServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.print("----------1-------");
System.out.print("--------2---------");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
}
%>
servlet jsp 类 web.xml java
------解决方案--------------------
可以的。
------解决方案--------------------
一个jsp写doPost干吗,想做什么直接做,想接值直接写request.getParameter
------解决方案--------------------
其实可以在jsp中使用
<%!
public void method(){