java - Simple JavaEE HTML GET/POST application -


i'm starting out javaee (i'm decently fluent in javase) , having trouble wrapping brain around new things required make simplest of applications. right trying use jax-rs annotations generate simple "hello world" html page in intellij using glassfish 4. i've searched around proper use of these annotations, , seems i'm doing correctly, keep getting 404 no matter navigate in localhost. i'm starting think i'm missing vital components in code, , don't know enough javaee know i'm missing (perhaps in web xml file, don't know about). here code wrote, minus imports:

@localbean @stateless @path("/hello") @produces("text/html") public class hello {      @get     @path("/world")     public string printhelloworld() {         return "<html lang=\"en\"><body><h1>hello, world!</h1></body></html>";     } } 

the server , running , application seems deploy correctly. default url set @ launch time "http://localhost:8080/helloworld_war_exploded/", understanding should going http://localhost:8080/helloworld_war_exploded/hello/world display message.

if point me in right direction great. thanks!

edit: here xml file, did not change @ all:

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"          version="3.1">     <servlet>         <servlet-name>faces servlet</servlet-name>         <servlet-class>javax.faces.webapp.facesservlet</servlet-class>         <load-on-startup>1</load-on-startup>     </servlet>     <servlet-mapping>         <servlet-name>faces servlet</servlet-name>         <url-pattern>*.xhtml</url-pattern>     </servlet-mapping> </web-app> 

upon looking @ lutz's comment, i've investigated base url issue , viewing following link (can't link more twice points): hxxp://www-01.ibm.com/support/knowledgecenter/ssaw57_8.5.5/com.ibm.websphere.nd.doc/ae/twbs_jaxrs_configwebxml.html?cp=ssaw57_8.5.5%2f1-3-0-28-2-0-1

i update accordingly. help!

you need configure jersey (the jax-rs implementation in glassfish) in web.xml. have jsf configuration

<servlet>     <servlet-name>jersey-serlvet</servlet-name>     <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class>     <init-param>         <param-name>jersey.config.server.provider.packages</param-name>         <param-value>the.package.where.your.resources.are</param-value>     </init-param>     <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping>     <servlet-name>jersey-serlvet</servlet-name>     <url-pattern>/api/*</url-pattern> </servlet-mapping> 

the <url-mapping> base jersey app. use

http://localhost:8080/helloworld_war_exploded/api/hello/world 

if want use standard jax-rs configuration, can

<servlet>     <servlet-name>javax.ws.rs.core.application</servlet-name> </servlet>  <servlet-mapping>     <servlet-name>javax.ws.rs.core.application</servlet-name>     <url-pattern>/api/*</url-pattern> </servlet-mapping> 

this scan entire classpath resources, don't need specify package, previous configuration.

or can use java code

@javax.ws.rs.applicationpath("/api") public class restapplication extends javax.ws.rs.core.application {  } 

leaving class empty scan entire classpath resources. or can add classes explicitly

@javax.ws.rs.applicationpath("/api") public class restapplication extends javax.ws.rs.core.application {      @override      public set<class<?>> getclasess() {          set<class<?>> classes = new hashset<>();          classes.add(hello.class);          return classes;      } } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -