通过JSP将变量传递给Java?
我想知道是否可以将表单数据从index.jsp 文件传递到java 类,然后返回到response.jsp。我试图用他们输入到index.jsp的数据来计算一些东西,但它不能在Javascript中完成。有没有办法可以检索数据?
另一件事是使用 http 服务器并用 Java 编写整个 html,但这似乎过于复杂,如果有更简单的方法来做到这一点,那么不值得付出努力。
预先感谢您的帮助!
这是我编写的尝试解决此问题的脚本之一(在 JavaScript 中),但我的类 RunPython.java 总是出现错误?
<script type="text/javascript">
function onSubmit(){
var Bugfile = document.forms[0]["BugFile"].value;
var GD = document.forms[0]["GD"].value;
<%
String s = request.getParameter("Bugfile");
String d = request.getParameter("GD");
RunPython re = new RunPython(s,d);
%>
}
错误:
org.apache.jasper.JasperException: PWC6033: JSP PWC6197 的 Javac 编译出错
:jsp 文件中的第 61 行发生错误:/index.jsp PWC6199:生成的 servlet 错误: string:///index_jsp.java:106: 找不到符号 符号:类 RunPython 位置:类org.apache.jsp.index_jsp
PWC6197:jsp文件中的第61行发生错误:/index.jsp PWC6199:生成的 servlet 错误: string:///index_jsp.java:106: 找不到符号 符号:类 RunPython 位置:类 org.apache.jsp.index_jsp
I'm wondering if it is possible to pass form data from index.jsp file to a java class and then back to the response.jsp. I'm trying to compute something with the data they have entered into index.jsp but it can't be done in Javascript. Is there a way that I can retrieve the data?
The other thing is using http servelts and writing the entire html in Java, but that seems overly complex and not worth the effort if there are simpler ways of doing this.
Thanks in advance for the help!
This is one of the scripts (in javascript) that I written to try and solve this problem, but my class, RunPython.java, always comes an error?
<script type="text/javascript">
function onSubmit(){
var Bugfile = document.forms[0]["BugFile"].value;
var GD = document.forms[0]["GD"].value;
<%
String s = request.getParameter("Bugfile");
String d = request.getParameter("GD");
RunPython re = new RunPython(s,d);
%>
}
Error:
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP
PWC6197: An error occurred at line: 61 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:106: cannot find symbol
symbol : class RunPython
location: class org.apache.jsp.index_jsp
PWC6197: An error occurred at line: 61 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:106: cannot find symbol
symbol : class RunPython
location: class org.apache.jsp.index_jsp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编译器只是试图告诉您它无法解析任何导入中提到的类。您需要在 JSP 中导入提到的类。
尽管您的尝试似乎相当笨拙,但这与传递变量无关有关,但这会引发一个新问题。
与具体问题无关,您似乎误解了 servlet 的目的和功能。他们并不打算将 HTML 完全写入其中。只是 Java 代码。从我们的 servlet wiki 页面开始了解它们。
The compiler is just trying to tell you that it cannot resolve the mentioned class in any of the imports. You need to import the mentioned class in JSP.
This has nothing to do with passing variables around, although your attempt seems to be pretty clumsy, but this is subject to a new question.
Unrelated to the concrete problem, you seem to misunderstand the purpose and capabilities of servlets. They are not meant to write the HTML entirely in it. Just only Java code. Start at our servlets wiki page to learn about them.