[英]JAVA - Is there possible pass a servlet value received to a .java file, but in another project?
good afternoon. 下午好。 I have a .JSP file that send a value to a servlet file.
我有一个.JSP文件,可将值发送到servlet文件。 I have another project, where there is a java file in that i want to get this servlet value received by .JSP file.
我有另一个项目,其中有一个Java文件,我想获取该.JSP文件接收的servlet值。
My question is if is there possible pass this servlet value to this .java file in another project ? 我的问题是,是否有可能将此servlet值传递给另一个项目中的.java文件? Or can i send by .JSP file directly ?
还是可以直接通过.JSP文件发送?
I created a Java Class in my Web Application, but now, how can i pass the servlet parameter to this java class ? 我在Web应用程序中创建了一个Java类,但是现在,如何将servlet参数传递给该Java类?
I will put the code down here: 我将代码放在这里:
Servlet code: Servlet代码:
public class ServletJava extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
/*I WANT TO INSTANCE THE PARAMETER HERE TO SEND TO OTHER CLASS*/
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
public String getServletInfo() {
return "Short description";
}
}
The Class java: 类java:
public class RecebeServlet {
public static void main(String[] args) throws Exception {
/*I WANT RECEIVE THE PARAMETER HERE !! */
}
}
It is probably bad practice to have a class with only one main mathod. 上一堂课只有一个主要方法可能是不好的做法。 I am sure that you can divide the logic from that class into several methods instead of having one giant
main
. 我敢肯定,您可以将该类的逻辑分为几种方法,而不用拥有一个庞大的
main
。
But anyway, since you asked: Just call your main
method as you would call any static method: 但是无论如何,既然您问过:就像调用任何静态方法一样,只需调用
main
方法即可:
String[] args = new String[1];
args[0] = yourValue;
RecebeServlet.main(args);
But again, please consider refactoring your RecebeServlet
class. 但同样,请考虑重构您的
RecebeServlet
类。 You do not want to have program logic in your main method. 您不想在主方法中包含程序逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.