[英]set init params to jsp page without web.xml
I know that I can set init params for a jsp page using web.xml. 我知道我可以使用web.xml为jsp页面设置初始化参数。 For example
例如
<servlet>
<servlet-name>init</servlet-name>
<jsp-file>/init.jsp</jsp-file>
<init-param>
<param-name>test</param-name>
<param-value>me</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>init</servlet-name>
<url-pattern>/init.jsp</url-pattern>
</servlet-mapping>
then in my init.jsp I can get the init params using getServletContext.getInitParameter.. 然后在我的init.jsp中,我可以使用getServletContext.getInitParameter获得初始化参数。
However, I am using WebSevlet 3.0 annotations and I can't see equivalent jsp-file annotation. 但是,我使用的是WebSevlet 3.0批注,看不到等效的jsp文件批注。 I am looking for something along these lines
我正在寻找符合这些条件的东西
@WebServlet(initParams=@WebInitParam(name="hello", value = "hello"),description = "A Simple Servlet", urlPatterns = { "/init.jsp" })
where I can use jsp-file annotation. 在这里我可以使用jsp文件注释。 So I need to set the jsp init params without using web.xml.
因此,我需要在不使用web.xml的情况下设置jsp初始化参数。
I know you said without using a web.xml - but you could still use a web.xml file with annotations - and just use it for the parameters - define the init params as a context-param. 我知道您说的是不使用web.xml-但是您仍然可以使用带有批注的web.xml文件-并将其用作参数-将初始化参数定义为上下文参数。 That would set the parameter for the whole application...
那将为整个应用程序设置参数...
<context-param>
<param-name>someParameter</param-name>
<param-value>someValue</param-value>
</context-param>
Then in your code - reference it in the same way as above : 然后在您的代码中-以与上述相同的方式引用它:
getServletContext.getInitParameter("someParameter");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.