Eclipse和JSP编程。在哪里存储课程? [英] Eclipse and JSP programing. Where to store classes?

查看:211
本文介绍了Eclipse和JSP编程。在哪里存储课程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Eclipse学习一些JSP编程,我遇到一些问题:



这是我有的:

1)在WebContent文件夹中的test.jsp文件,只显示Hello World!。我选择了文件并单击运行方式。要求我重新启动Tomcat服务器。点击是的,在Eclipse中打开的页面显示Hello World!。

2)我写了Car类并将其存储在Java Resources / src中

3)试图引用Car类我测试JSP和一切似乎是对的。 (代码如下)

 <%@ page import =ws.example。*%> 
<%
汽车myCar =新车(闪避,霓虹灯);
out.println(myCar.getMake());
&>

4)再次单击运行,我收到了Hello World消息。点击刷新,错误显示该车MyCar =新车(闪避,霓虹灯);无法解析为类型。

5)再次点击刷新2次,第二次Hello World!出现了。

6)保持点击刷新按钮,有时我会有错误,有时你好世界。我知道你好,世界是从现金来的,但是我该如何避免呢?非常烦人。



问题:

1)当我在项目中进行更改时,如何确保这些更改包含在启动时项目?

2)存放课程的好地方在哪里?显然,我尝试没有工作。



更新:



我的课程:

  package ppp; 

public class MyCar {

String make;
字符串模型;

public MyCar(String make,String model){
this.make = make;
this.model = model;
}

public String getMake()
{
return make;

}
public String getModel()
{
返回模型;
}
}

这里是我的JSP代码(NewFile.jsp):

 <%
ppp.MyCar car = new ppp.MyCar(,);
%>

项目结构:

  TestProject 
- 部署描述符:TestProject
- Java资源
- src
- MyCar.java
- 库
- .. 。
- JavaScript资源
- build
- WebContent
- META-INF
- WEB-INF
- NewFile.jsp

我没有看到任何错误的空间。



谢谢

解决方案


1)当我改变项目时,我该怎么做确保在启动项目时会包含这些更改?


重新发布服务器。这是服务器在服务器视图中的右键菜单选项。如果无效,重建项目并清理服务器。您可以在服务器的属性中配置自动发布。





服务器的作用如何取决于服务器make / version和插件。例如,Tomcat是一个糟糕的发行商,你宁愿只是重新启动服务器。 Glassfish与其插件是一个巨大的出版商,它基本上是实时发生的。



顺便说一下,我从来没有使用运行为选项或Eclipse的内置浏览器。它被认为是一个穷人。我只是启动服务器,然后在我自己喜欢的webbrowser(例如Firefox,Chrome等)中打开页面。







2)存放课程的好地方在哪里?显然,我尝试没有工作。


在运行时类路径中的一个包中通常的方式。 / p>




与具体问题无关:尝试使用命名约定(类名应以大写开头),并尝试将Java代码放在JSP中(这是一个很差的做法)。


I am trying to learn some JSP programming with Eclipse and I am having some issues:

Here is what I have:
1) Have test.jsp file inside WebContent folder that simply displays "Hello World!". I selected file and clicked Run As. Asked me to restart Tomcat server. Clicked Yes and page opened inside Eclipse showing "Hello World!".
2) I wrote Car class and stored it inside Java Resources/src
3) Tried to reference Car class in my test JSP and everything seemed right. (code below)

<%@ page import="ws.example.*" %>
<%  
    car myCar = new car("dodge", "neon");
    out.println(myCar.getMake());
&>

4) Clicked "Run As" again and I got Hello World message. Clicked refresh, error showed up that car MyCar = new car("dodge", "neon"); cannot be resolved to a type.
5) Clicked Refresh again 2 times and second time message "Hello World!" showed up.
6) Kept clicking Refresh button and sometime I would have error, sometime Hello World. I understand that Hello World is coming from cash, but how can I avoid this? Very annoying.

Questions:
1) When I make change in my project, how can I make sure those changes are included when I start the project?
2) Where is the good place to store your classes? Obviously what I try didn't work.

UPDATED:

Here is my class:

package ppp;

public class MyCar {

    String make;
    String model;

    public MyCar(String make, String model) {
        this.make = make;
        this.model = model;
    }

    public String getMake()
    {
        return make;

    }
    public String getModel()
    {
        return model;
    }
}

here is my JSP code (NewFile.jsp):

<%
    ppp.MyCar car = new ppp.MyCar("", "");
%>

Project Structure:

 TestProject  
     - Deployment Descriptor: TestProject  
     - Java Resources  
         - src  
             - MyCar.java   
         - Libraries  
             - ...  
     - JavaScript Resources    
     - build  
     - WebContent  
         - META-INF
         - WEB-INF
         - NewFile.jsp

I just don't see any room for error here.

thanks

解决方案

1) When I make change in my project, how can I make sure those changes are included when I start the project?

Republish the server. It's an rightclick menu option of the server in Servers view. If in vain, rebuild the project and clean the server. You can configure automatic publishing in the server's properties.

How servers act on this depends on the server make/version and the plugin. For example, Tomcat is a poor publisher, you'd rather like to just restart the server. Glassfish with its plugin is a tremendous publisher, it basically happens realtime.

By the way, I never use Run as option nor Eclipse's builtin browser. It's known to be a poor one. I just start the server and then open the page in my own favourite webbrowser (e.g. Firefox, Chrome, etc).


2) Where is the good place to store your classes? Obviously what I try didn't work.

Just in a package somewhere in the runtime classpath the usual way.


Unrelated to the concrete problem: try working on your naming conventions (classnames should start with uppercase) and try to avoid putting Java code in JSP (it's a very poor practice).

这篇关于Eclipse和JSP编程。在哪里存储课程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆