简体   繁体   English

在Web应用程序中使用.JAR文件

[英]Using .JAR file within Web Application

I am trying to learn how to develop web applications and I am a little stuck. 我正在尝试学习如何开发Web应用程序,但我有些困惑。

I want to create a movie review application. 我想创建一个电影评论应用程序。 It has a few java class/packages which is inside a JAR file: moviewebapp.jar package - moviewebapp.movie class - Movie.class 它在JAR文件中有一些Java类/程序包:moviewebapp.jar程序包-moviewebapp.movi​​e类-Movie.class

package - moviewebApp.servlet MovieServlet.class 包-moviewebApp.servlet MovieServlet.class

And a servlet class which has methods such as doPost, doGet, getMovie, updateMovie etc. 还有一个servlet类,该类具有诸如doPost,doGet,getMovie,updateMovie等方法。

I have added the .JAR file to my build path. 我已经将.JAR文件添加到了我的构建路径。

I have developed a simple page where a user can click add movie review, which opens up a form where they can input the movie name and rating. 我开发了一个简单的页面,用户可以单击添加电影评论,这会打开一个表单,供他们输入电影名称和等级。

I now want to save the users input to a datastore. 我现在想将用户输入保存到数据存储中。 How do I use the methods within the servlet class in my javascript to deal with the post of the information about the movie? 如何使用JavaScript的Servlet类中的方法来处理有关电影的信息发布?

I have tried doing imports and then trying to create a servlet object but I dont think I have the correct syntax or maybe thats not how I'm meant to do it. 我曾尝试进行导入,然后尝试创建servlet对象,但我认为我没有正确的语法,或者那不是我的意图。

Any help would be appreciated! 任何帮助,将不胜感激!

Jars are libraries you should not modify its code unless untill it is last option. Jar是库,除非它是最后的选择,否则您不应修改其代码。 You can import it's classes and use methods of those classes. 您可以导入它的类并使用这些类的方法。 By your question it seems you are new to Java. 通过您的问题,看来您是Java的新手。 So I suggest you should start with hello world tutorials of servers and jdbc then start developing applications. 因此,我建议您应该先从服务器和jdbc的世界教程开始,然后再开始开发应用程序。 Good luck. 祝好运。

Trying to provide some guidance: 尝试提供一些指导:

Easiest solution (not the best) : you have to submit your page to receive the entry from the user. 最简单的解决方案(不是最好的):您必须提交页面以接收用户的输入。 Doing this you are going to lose the status of the page on the client side. 这样做会丢失客户端页面的状态。

A better solution is to make a asynchronous javascript request to get the answer provided by the user for you to process on the server side. 更好的解决方案是发出一个异步javascript请求,以获取用户提供的答案,以便您在服务器端进行处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM