Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript RESTMaven项目上jsp页面的CRUDGUI_Javascript_Java_Rest_Maven_Jsp - Fatal编程技术网

Javascript RESTMaven项目上jsp页面的CRUDGUI

Javascript RESTMaven项目上jsp页面的CRUDGUI,javascript,java,rest,maven,jsp,Javascript,Java,Rest,Maven,Jsp,我正在为一个maven项目的GUI而努力。通过JUnit测试,我知道整个系统运行良好。虽然我知道这不是最好的方法,但我已经尝试了各种各样的事情,我现在要展示给大家看。必须有更简单的方法来做到这一点 好的..我已经连接到数据库,我可以用字符串或对象将所有信息返回到JSP页面,两者都不理想,因为对象将在列表的任意一侧返回[]括号,字符串并不理想,因为我可能希望在每个条目旁边使用删除和更新按钮 即时检索字符串和对象 index.jsp <p><a href="webapi/cds"&

我正在为一个maven项目的GUI而努力。通过JUnit测试,我知道整个系统运行良好。虽然我知道这不是最好的方法,但我已经尝试了各种各样的事情,我现在要展示给大家看。必须有更简单的方法来做到这一点

好的..我已经连接到数据库,我可以用字符串或对象将所有信息返回到JSP页面,两者都不理想,因为对象将在列表的任意一侧返回[]括号,字符串并不理想,因为我可能希望在每个条目旁边使用删除和更新按钮

即时检索字符串和对象

index.jsp

<p><a href="webapi/cds">All Entries</a></p>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
     see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>Assignment.rest</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/webapi/*</url-pattern>
    </servlet-mapping>

</web-app>

Jersey Web应用程序
org.glassfish.jersey.servlet.ServletContainer
jersey.config.server.provider.packages
作业.休息
1.
Jersey Web应用程序
/webapi/*
new.jsp

<b><%= request.getParameter("test") %></b>

<b><%= request.getAttribute("test1") %></b>

光盘资源

@GET
    @Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
    public Response getAllCDs()
    {
        List<CD> list = cdRepos.findAllCD();

        String sentence="";

        for (CD c: list)
        {
            sentence+="ID : "+c.getId()+"<br>Artist : "+c.getArtistName()+"<br>Title : "+c.getTitle()+"<br>Duration : "+c.getDuration()+"<hr>";
        }

        URI uri = UriBuilder.fromPath("/rest/new.jsp")
                .queryParam("test", list)
                .build();
        return Response.seeOther(uri).build();



//      return list; //this returns the cd list in json
//      java.net.URI location = null;
//      try {
//          location = new java.net.URI("http://localhost:8080/rest/new.jsp");
//      } catch (URISyntaxException e) {
//          // TODO Auto-generated catch block
//          e.printStackTrace();
//      }
//      CD cdt = new CD();
//      cdt.setArtistName("hello World");
//      return  Response.temporaryRedirect(location).entity(cdt).build();
    }
@GET
@产生({MediaType.APPLICATION_JSON,MediaType.TEXT_PLAIN})
公共响应getAllCDs()
{
List=cdRepos.findalcd();
字符串句子=”;
用于(CD c:列表)
{
句子+=“ID:+c.getId()+”
艺术家:“+c.getArtistName()+”
标题:“+c.getTitle()+”
持续时间:“+c.getDuration()+”
”; } URI=UriBuilder.fromPath(“/rest/new.jsp”) .queryParam(“测试”,列表) .build(); 返回Response.seeOther(uri.build(); //return list;//返回json格式的cd列表 //java.net.URI location=null; //试一试{ //location=新的java.net.URI(“http://localhost:8080/rest/new.jsp"); //}catch(URISyntaxException e){ ////TODO自动生成的捕捉块 //e.printStackTrace(); // } //CD cdt=新CD(); //cdt.setArtistName(“你好世界”); //返回Response.temporaryRedirect(location).entity(cdt.build(); }
CDClient.java

public CD get(String id)
{
    System.out.println("ye getting to here");
    WebTarget target =  client.target("http://localhost:8080/rest/webapi/");

    Response response = target.path("cds/"+id).request(MediaType.APPLICATION_JSON).get(Response.class);


    if(response.getStatus() != 200)
    {
        throw new RuntimeException(response.getStatus()+ " there was an error on the server");
    }
    return response.readEntity(CD.class);
}

public List<CD> get()
{
    WebTarget target =  client.target("http://localhost:8080/rest/webapi/");
    List<CD> response = target.path("cds").request(MediaType.APPLICATION_JSON).get(new GenericType<List<CD>>(){});



    return response;
}
公共CD获取(字符串id) { System.out.println(“你到这里了”); WebTarget=client.target(“http://localhost:8080/rest/webapi/"); Response-Response=target.path(“cds/”+id).request(MediaType.APPLICATION_JSON).get(Response.class); if(response.getStatus()!=200) { 抛出新的RuntimeException(response.getStatus()+“服务器上有错误”); } 返回response.readEntity(CD.class); } 公共列表get() { WebTarget=client.target(“http://localhost:8080/rest/webapi/"); List response=target.path(“cds”).request(MediaType.APPLICATION_JSON).get(new-GenericType(){}); 返回响应; }
请和感谢

我很困惑,你能清楚你想要什么吗?我正在寻找更好的方法,为我制作的CRUD程序制作jsp页面gui的最佳方法是什么我认为REST很好,你可以使用正确的http方法为任何操作创建端点,并通过Ajax调用访问它,使用Jquery或类似的东西。