Avatar billede ascii Nybegynder
04. marts 2002 - 23:15 Der er 8 kommentarer og
1 løsning

Hjælp til nybegynder!!

Jeg skal til at ha lært lidt om jsp. Håber så at der er nogle der vil hjælpe mig igang

Har installeret Resin, og bruger også Resin's webserver.. "virker"
Nu skal jeg så til at lave en simpel side, for at komme igang..

Min config-fil ser ud som følgende..

<!--
  - The Resin configuration file.
  -
  - This example file is more complicated than is needs to be because
  - it makes several configurations explicit that can be simplified and
  - because it needs to configure the examples.
  -
  - Look in conf/samples for more realistic sample configurations.
  -  conf/samples/simple.conf - a simple, basic configuration
  -  conf/samples/deploy.conf - a simple configuration for deployment
  -
  - The configuration is based on a purely element-based XML.  To make
  - it easier to read, attributes can be used as syntactic sugar.
  -
  - The following are equivalent:
  - <foo><bar>13</bar></foo>  - canonical representation, but verbose
  - <foo bar=13/>            - typical configuration
  - <foo><bar id=13/></foo>  - sometimes useful
  -->
<caucho.com>

<!--
  - Resin logging.  Debugging is also available with different values
  - for id.
  -->
<log id='/log' href='stderr:' timestamp='[%Y-%m-%d %H:%M:%S.%s]'/>

<!-- Security providers.  Adding JSSE looks like:
  - <security-provider id='com.sun.net.ssl.internal.ssl.Provider'/>
  -->

<!--
  - You can change the compiler to "javac" or jikes.
  - The default is "internal" only because it's the most
  - likely to be available.
  -->
<java compiler="internal" compiler-args=""/>

<!--
  - Sample database pool configuration
  - The JDBC name is java:comp/env/jdbc/test
  -->
<resource-ref>
  <res-ref-name>jdbc/test</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <init-param driver-name="com.caucho.jdbc.mysql.Driver"/>
  <init-param url="jdbc:mysql_caucho://localhost:3306/test"/>
  <init-param user=""/>
  <init-param password=""/>
  <init-param max-connections="20"/>
  <init-param max-idle-time="30"/>
</resource-ref>

<!--
  - Use precompiled JSP classes if available.
  - 'static-encoding' - optimization if you stick to one character set
  -->
<jsp precompile='true' static-encoding='true' recompile-on-error='true'/>

<http-server>
  <!--
    - The root file directory of the server.  Apache users will change
    - this to /usr/local/apache/htdocs and IIS users will change it
    - to d:\inetpub\wwwroot
    -->
  <app-dir>C:\web</app-dir>
 
  <!-- the http port -->
  <http port='80'/>

  <!--
    - The srun port, read by both JVM and plugin
    - 127.0.0.1 is the localhost
    -->
  <srun host='127.0.0.1' port='6802'/>

  <!--
    - How to add SSL:
    -
    - <http port=8443>
    -  <ssl>true</ssl>
    -  <key-store-type>pkcs12</key-store-type>
    -  <key-store-file>keys/server_cert.p12</key-store-file>
    -  <key-store-password>changeit</key-store-password>
    - </http>
    -->

  <!--
    - For production sites, change class-update-interval to something
    - like 60, so it only checks for updates every minute.
    -->
  <class-update-interval>2</class-update-interval>

  <!--
    - If true, the classloader order follows the Servlet spec.
    - If false, the classloader order follows the JDK spec.
    -->
  <servlet-classloader-hack>false</servlet-classloader-hack>

  <!--
    - Select an error page to display when the connection fails.
    -
    - <error-page exception='connection' location='/my-error-page.html'/>
    -->

  <!-- To disable /caucho-status, set this to false -->
  <caucho-status>true</caucho-status>

  <!-- maximum number of threads -->
  <thread-max>150</thread-max>

  <!--
    - How many threads to wait for keepalives.  Should be at least the
    - number of Apache processes to get good performance.
    -->
  <thread-keepalive id='100'/>

  <!--
    - How long an idle keepalive connection should listen to the socket.
    -->
  <request-timeout id='30s'/>

  <!--
    - How many sockets to hold in the buffer before failing requests.
    -->
  <accept-buffer-size id='256'/>
  <!--
    - Maximum number of request threads which will wait for a socket.
    -->
  <thread-min id='5'/>

  <!--
    - Ping to test if the web server is still up.  You can uncomment this
    - and point it to pages on the webserver that exercise your main
    - logic (like database access).  If the GET fails, it will restart
    - the server.  This will catch deadlocks, but not JDK freezes.
    -
    - <ping sleep-time='1m' retry-count='3' retry-time='1s'>
    -  <url>http://localhost:8080/ping/ping.jsp</url>
    - </ping>
    -->

  <!--
    - Enables/disables exceptions when the browser closes a connection.
    -->
  <ignore-client-disconnect>true</ignore-client-disconnect>

  <!--
    - Enable internal caching.
    - 'dir' is the directory containing the cache
    - 'size' is the memory size in kb
    - 'entries' is the total number of entries
    -->
  <cache dir='cache' size='1024' entries='8192'/>

  <!--
    - Expires time for a cacheable file.  Production sites will
    - normally change this to '15m'
    -->
  <cache-mapping url-pattern='/' expires='2s'/>

  <!--
    - servlet configuration outside the <host> is a default for all hosts.
    -->
  <servlet-mapping url-pattern='*.xtp' servlet-name='xtp'/>
  <servlet-mapping url-pattern='*.jsp' servlet-name='jsp'/>

  <!--
    - set the pages to be used as welcome (index) files
    -->
  <welcome-file-list>index.xtp, index.jsp, index.html</welcome-file-list>

  <!-- default host if no other host matches -->
  <host id=''>
    <!--
      - The standalone server should uncomment for access logging.
      - With another web server, like Apache, the web server will
      - log this information.
    <access-log id='log/access.log'
          format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'/>
      -->

    <error-log id='log/error.log'/>

    <!--
      - Specifies an automatically-expanding .war dir.  Any foo.war
      - file will be expanded to a /foo application.
      -->
    <war-dir id='webapps'/>

    <web-app id='/'>
      <!--
        - The classpath directive may be repeated.  Source is optional
        - Servlets and beans generally belong in WEB-INF/classes
        -->
      <classpath id='WEB-INF/classes'
                source='WEB-INF/classes'
                compile='true'/>

      <session-config>
        <session-max>4096</session-max>
        <session-timeout>30</session-timeout>
        <enable-cookies>true</enable-cookies>
        <enable-url-rewriting>true</enable-url-rewriting>

        <!--
          - Store sessions in the filesystem, so they can persist across
          - servlet and class changes.
          -
          - Uncomment this during development.
          -->
        <!--
          -  <file-store>WEB-INF/sessions</file-store>
          -->
      </session-config>

      <!-- enable multipart-mime/form processing -->
      <!--
        - <multipart-form upload-max='-1'/>
        -->

      <!-- /~user maps to user directories -->
      <path-mapping url-regexp='^/~([^/]*)' real-path='/home/$1/public_html/'/>
    </web-app>

    <!--
      - The following entries configuration the examples.  You may safely
      - delete anything from here down.
      -->

    <!--
      - Define applications (ServletContexts) for the examples.
      - Since applications are entirely separate from one another,
      - including session variables and servlet-mappings, the
      - servlet-mapping declarations need to be repeated.
      -->
    <web-app id='java_tut'/>

    <web-app id='examples/basic'>
      <!-- Application init parameters, see Env.java to get the values -->
      <context-param info='An application information string'/>

      <!--
        - The "invoker" servlet invokes servlet classes from the URL.
        - /examples/basic/servlet/HelloServlet will start the HelloServlet
        - class.  In general, the invoker should only be used
        - for development, not on a deployment server, because it might
        - leave open security holes.
        -->
      <servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>

      <!-- snoop-servlet handles all urls starting with /snoop -->
      <servlet-mapping url-pattern='/snoop/*' servlet-name='snoop-servlet'/>

      <!-- configure snoop-servlet with init parameters -->
      <servlet servlet-name='snoop-servlet' servlet-class='Env'>
        <init-param info='A servlet information string'/>
      </servlet>
    </web-app>

    <web-app id='examples/tags'/>

    <web-app id='examples/tictactoe'/>

    <web-app id='examples/navigation'/>

    <web-app id='examples/xsl'/>

    <web-app id='examples/templates'>
      <servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>
      <servlet-mapping url-pattern='/GuestJsp' servlet-name='GuestJsp'/>
      <servlet-mapping url-pattern='/GuestXtp' servlet-name='GuestXtp'/>
      <servlet-mapping url-pattern='/RSS' servlet-name='jsp.RSS'/>

      <servlet servlet-name='GuestJsp' servlet-class='jsp.GuestJsp'/>
      <servlet servlet-name='GuestXtp' servlet-class='jsp.GuestXtp'/>
    </web-app>

    <web-app id='/examples/login'/>
  </host>

  <!--
    - Known broken browsers.  These should no longer be necessary, but
    - you can uncomment them if they become a problem.
    -
    - <browser-mapping regexp="MSIE 4\.0b2" force10/>
    - <browser-mapping regexp="RealPlayer 4\.0" force10/>
    - <browser-mapping regexp="Java/1\\.0" force10/>
    - <browser-mapping regexp="JDK/1\\.0" force10/>
    -->
</http-server>
</caucho.com>


Har ændret dir til Web-server. Er det ok..
Hvad mangler for at kunne lave en simpel jsp-fil..
Skal webserver dir ændres så det ligger i WEB-INF

Ved godt det er helt fra bunden, men mangler ligesom et sted at starte...

Ascii
Avatar billede disky Nybegynder
05. marts 2002 - 00:01 #1
Nej webserver dir skal ikke ændres.

lav en jsp med følgende indhold


<%
String text="Hello world";
%>

text = <%=text%>


Hvis den skriver

text = Hello world

Så virker det.
Avatar billede disky Nybegynder
05. marts 2002 - 00:22 #2
app-dir skal pege derhen hvor dine JSP sider ligger og i denne skuffe skal der være en skuffe der hedder WEB-INF og inde i den en der hedder 'classes' det er det hele.
Avatar billede ascii Nybegynder
05. marts 2002 - 07:22 #3
Det virker ikke... Men jeg kan jo heller ikke bare lave en tekstdokument der hedder test.jsp, eller hvad...
Den skriver det her "JDK tools.jar is missing from the classpath"
Hvordan skal min Sample database pool configuration se ud....
såddan her::
<!--
  - Sample database pool configuration
  - The JDBC name is java:comp/env/jdbc/test
  -->
<resource-ref>
  <res-ref-name>jdbc/test</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <init-param driver-name="org.gjt.mm.mysql.Driver"/>
  <init-param url="localhost:3306/kundeDB"/>
  <init-param user="root"/>
  <init-param password="root"/>
  <init-param max-connections="20"/>
  <init-param max-idle-time="30"/>
</resource-ref>

<!--

Har den ikke selv JDBC driveren..
Avatar billede ascii Nybegynder
05. marts 2002 - 15:07 #4
Nu har jeg installeret j2sdk og tilføjet den i classpath..

lavet en jsp fil som ligger i web\
<%
String text="Hello world";
%>

text = <%=text%>

Når jeg kører den i browser giver den følgende fejl

Resin can't execute the compiler `javac'.  This usually means that the
compiler is not in the operating system's PATH or the compiler is incorrectly
specified in the configuration.  You may need to add the full path to <java
compiler='javac'/>.

java.io.IOException: CreateProcess: javac -classpath C:\web\WEB-INF\work;classes;lib\resin.jar;lib\dom.jar;lib\jaxp.jar;lib\jdbc-mysql.jar;lib\jdbc2_0-stdext.jar;lib\jndi.jar;lib\jsdk23.jar;lib\jta-spec1_0_1.jar;lib\sax.jar;lib\webutil.jar;C:\programmer\JBuilder3\java\jre\lib\rt.jar;C:\programmer\JBuilder3\java\jre\lib\i18n.jar;C:\programmer\JBuilder3\java\jre\classes;C:\web\WEB-INF\classes;\temp\caucho
-d C:\web\WEB-INF\work C:\web\WEB-INF\work\_view_0source__jsp.java  error=2

CLASSPATH =  JAVA_HOME C:\jdk1.3.1_02
path = ;%JAVA_HOME%\bin

Har rettet conf fil så den bruger javac,
Avatar billede ascii Nybegynder
05. marts 2002 - 15:24 #5
Nu virker det.. har skrevet hele stien til javac i conf.

Alle classfiler skal ligge i WEB-INF\classes ikke
Avatar billede ascii Nybegynder
05. marts 2002 - 16:18 #6
Det jeg postede før med databasen.... 
De her to linier forstår jeg ikke, "har læst dokumentationen."
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
Er de korrekte??
Avatar billede disky Nybegynder
07. marts 2002 - 19:36 #7
der ser korrekt ud.

min er sådanne her:
<resource-ref>
  <res-ref-name>jdbc/test</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <init-param driver-name="com.caucho.jdbc.mysql.Driver"/>
  <init-param url="jdbc:mysql_caucho://localhost:3306/test"/>
  <init-param user=""/>
  <init-param password=""/>
  <init-param max-connections="20"/>
  <init-param max-idle-time="30"/>
</resource-ref>


Jeg bruger dog mysql direkte inde fra mit java kode
Avatar billede ascii Nybegynder
07. marts 2002 - 19:47 #8
<html>
<head>
    <title>test at mysql</title>
</head>
<%@ page language="java" import="java.sql.* , mysqldriver.*" %>
<body>
<h1> TEST info fra mysql-database</h1>
<table border="1" width="400">
<tr>
<td><b> test</b></td><td><b>test2</b></td>
<td><b> test3</b></td>
</tr>
<% //step1
Class.forName("org.gjt.mm.mysql.Driver");
//step2
Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost/kundeDB","root","root");
//step3
Statement stmt = myConn.createStatement();
//step4
ResultSet myResultSet = stmt.executeQuery("select * from kunde");
//step6
if(myResultSet != null)
{
//step7
while(myResultSet.next())
{
String test = myResultSet.getString("test");
String test2 = myResultSet.getString("test2");
String test3 = myResultSet.getString("test3");
%>
<tr>
<td><%= test %></td>
<td><%= test2 %></td>
<td><%= test3 %></td>
</tr>

<%
//step8
}
}

//step 9 og 10

stmt.close();
//step11
myConn.close();
%>


</table>


</body>
</html>
Avatar billede ascii Nybegynder
07. marts 2002 - 19:48 #9
Den er taget her fra eksperten
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester