java的servlet提取param的value值
out.println("<HTML>");out.println("<HEAD><TITLE>AServlet</TITLE></HEAD>");out.println...
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.print(this.getServletConfig().getInitParameter("param"));
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
为什么的提取的value是null? 展开
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.print(this.getServletConfig().getInitParameter("param"));
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
为什么的提取的value是null? 展开
4个回答
展开全部
在servlet中可以通过代码分别取用: 第二种参数只能在servlet的init()方法中通过this.getInitParameter("param1")取得:
package com.qisentech.controller;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
public class MainServlet extends HttpServlet {
public MainServlet() {
super();
}
public void init() throws ServletException {
System.out.println(this.getInitParameter("param1"));
System.out.println(getServletContext().getInitParameter("context/param"));
}
}
展开全部
out.print(this.getServletConfig().getInitParameter("param"));
中变量的名字是不是打错了?你jsp(或者html)中的变量名字叫什么啊?你只贴这一段只能让我猜了。
中变量的名字是不是打错了?你jsp(或者html)中的变量名字叫什么啊?你只贴这一段只能让我猜了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
initParameter的值是需要在web.xml里面定义这个servlet的时候一起定义的,就像这样
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>mypackage.LoginServlet</servlet-class>
<init-param>
<param-name>classname</param-name>
<param-value>com.ibm.db2.jcc.DB2Driver</param-value>
</init-param>
<init-param>
<param-name>url</param-name>
<param-value>jdbc:db2://localhost:50000/sample</param-value>
</init-param>
<init-param>
<param-name>user</param-name>
<param-value>db2admin</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>db2</param-value>
</init-param>
</servlet>
如果你要取classname就是this.getServletConfig().getInitParameter("classname"));
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>mypackage.LoginServlet</servlet-class>
<init-param>
<param-name>classname</param-name>
<param-value>com.ibm.db2.jcc.DB2Driver</param-value>
</init-param>
<init-param>
<param-name>url</param-name>
<param-value>jdbc:db2://localhost:50000/sample</param-value>
</init-param>
<init-param>
<param-name>user</param-name>
<param-value>db2admin</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>db2</param-value>
</init-param>
</servlet>
如果你要取classname就是this.getServletConfig().getInitParameter("classname"));
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
HttpServletRequest request = ServletActionContext.getRequest();
request.getParameter("你JSP或者HTML中变量的name值");
request.getParameter("你JSP或者HTML中变量的name值");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询