I have a simple rest webservice that will be used to load a page. Once the page is loaded the same page will be displayed with a confirmation msg or error msg being displayed.
Im using the using the below code to load it ....
jsp page:-
<form action="rest/file/upload" method="post"
enctype="multipart/form-data">
<br> <label>Username:    </label><input type="text"
placeholder="Username" name="username"> <br> <br>
<label>Password:     </label><input type="text"
placeholder="Password" name="password"> <br> <br>
<hr>
<p>
Select a file : <input type="file" name="file" size="45" />
</p>
<br> <input id="submit" type="submit" value="Upload" />
<c:out value="${obj}" />
<!-- ${obj} -->
</form>
controller
@Path("/file")
public class FileUploadService {
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Viewable uploadFile(
@Context HttpServletRequest request,@Context HttpServletResponse response,
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail,
@FormDataParam("username") String username,
@FormDataParam("password") String password) throws NoSuchAlgorithmException, IOException, URISyntaxException {
response.setHeader("Location", "/");
return new Viewable("/index.jsp",null);
web.xml
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Once I click the form the file is loaded and it takes back to the index.jsp page, but the location of the page is set to. RESTFileUpload is the program name.
http://localhost:8080/RESTFileUpload/rest/
but I want it to be
http://localhost:8080/RESTFileUpload/
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…